You are on page 1of 2

Practical -6.

// write a prgram to devlope a frame to selecte the different satest of indian


using JCombobox

import java.swing*;.

import java.awt.event.*;
public class ComboBoxExample implements ItemListener
{
JFrame f;
JLabel l;
ComboBoxExample()
{
l=new JLabel("This");
f=new JFrame("ComboBox Example");
String c[]={"Solapur","Pune","Banglore","Mumbai"};
JComboBox cb=new JComboBox(c); cb.setBounds(50,
50,90,20);
cb.addItem("Nashik");
cb.addItem("Nagar");
cb.addItemListener(this);
f.add(l);
l.setBounds(10, 10, 500,500);
f.add(cb);
f.setLayout(null);
f.setSize(400,500);
f.setVisible(true);
}
public void itemStateChanged(ItemEvent e)
{
String a=(String) e.getItem();
l.setText("your choice is " + a );
}
public static void main(String[] args) {
new ComboBoxExample();
}
}

practical 6.2
//Develpoe a program to demonstrate the use of scrollpane in swing
import java.awt.*;
import javax.swing.*;
public class JScrollDemo extends JApplet
{
public void init()
{
Container c=getContentPane(); JPanel
j=new JPanel(); j.setLayout(new
GridLayout(20,20)); for(int outer=0;
outer<=15;outer++)
{
for(int inner=0;inner<=15;inner++)
{
j.add(new JTextField("TextField" +outer+ "," +inner));
}
}
JScrollPane jsp=new JScrollPane(j);
jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ ALWAYS);
jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
c.add(jsp);
}
}
/*<appletcode=”JScrollDemo”
width=400 height=400>
</applet> */

You might also like