ADVANCE JAVA PROGRAMMING
Name :- Ayush Maroti Wadje Class : - CO5I
Roll No :- 76
Practical No 6 :- Write a Program Using Swing To Display a SrollPane and
JComboBox In An JApplet With The Items – English, Marathi, Hindi,
Sanskrit
X. ------------- ?
1. Write a Program Code To Generate The Following Output.
Code :-
import java.awt.*;
import javax.swing.*;
public class JComboEx1 extends JFrame {
JComboEx1() {
String city[]={"Mumbai","Pune","Bangalore","Solapur"};
JComboBox jcb=new JComboBox(city);
add(jcb);
jcb.setBounds(50,50,90,20);
Label l1=new Label("You Are In "+jcb.getSelectedItem());
add(l1);
setLayout(new GridLayout());
setSize(400,00);
setVisible(true);
}
public static void main(String args[]){
new JComboEx1();
}
}
1
Output :-
2
XIII. Exercise.
1.Write a Program To Develop a Frame To Select The Different States Of India
Using JComboBox
Code :-
import java.awt.*;
import javax.swing.*;
class states extends JFrame
{
JComboBox jcb;
String states[]={"Maharashtra","Goa","Ranchi","Bihar"};
states()
{
setLayout(new GridLayout());
setSize(400,350);
jcb=new JComboBox(states);
add(jcb);
}
public static void main(String[] args)
{
states s=new states();
s.setVisible(true);
}
}
3
Output :-
4
2.Develop a Program To Demonstrate The Use Of ScrollPane In Swings.
Code :-
import javax.swing.*;
import java.awt.*;
public class SP {
private static void GUI() {
final JFrame f = new JFrame();
f.setSize(500, 500);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().setLayout(new FlowLayout());
JTextArea t = new JTextArea(20, 20);
JScrollPane s1 = new JScrollPane(t);
s1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
s1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
f.getContentPane().add(s1);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
GUI();
}
});
}
}
5
Output :-