Name:- Priyanka Khandu Thadke
Class:-A(CO5I) Roll no:- 60
Practical no:-06 Write a java Program using swing to display a ScrollPane and JCombobox in
an JApplet with the items-English , Marathi , Hindi , Sanskrit.
Program Code:-
Q.1) Write a program code to generate following output.
Program:-
import [Link].*; import
[Link].*; import
[Link]; import
[Link];
public class ComboBoxE1 extends JFrame implements ItemListener{
JLabel l1;
public ComboBoxE1()
JComboBox cb = new JComboBox();
[Link]("Solapur");
[Link]("Pune");
[Link]("Banglore");
[Link]("Mumbai");
[Link](this);
l1 = new JLabel();
add(cb);
add(l1);
setSize(300,200);
setVisible(true);
setLayout(new FlowLayout());
public void itemStateChanged(ItemEvent ie)
String stateName = (String) [Link]();
[Link]("You are in" +stateName);
public static void main(String[] args)
{ new ComboBoxE1();
Output:-
Exercise:-
Q.1) Write a program to develop a frame to select the different states of India using
JComboBox.
Program:-
import [Link].*;
import [Link];
import [Link];
public class ComboBoxE2 extends JFrame{ public ComboBoxE2()
String s[]= {"Maharashtra","Rajastan","Gujrat","Punjab","Goa","Tamilnadu"};
JComboBox cb = new JComboBox<>(s);
[Link]("Maharashtra");
[Link]("Punjab");
[Link]("Rajastan");
[Link]("Goa");
[Link]("Gujrat");
add(cb);
setSize(300,200);
setLayout(new FlowLayout());
setVisible(true);
public static void main(String[] args) { new ComboBoxE2();
}
Output:-
Q.2) Develop a program to demonstrate the use of ScrollPane in Swings.
Program:-
import [Link].*;
import [Link].*;
import [Link];
import [Link];
import [Link];
public class ScrollPaneE3 extends JFrame{ public ScrollPaneE3()
setSize(400,300);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().setLayout(new FlowLayout());
JTextArea ta = new JTextArea(20,20);
JScrollPane s1 = new JScrollPane(ta);
[Link](JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
[Link](JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
getContentPane().add(s1);
public static void main(String[] args) {
new ScrollPaneE3();
Output:-