Practical 6
import [Link].*;
import [Link].*;
public class p61 extends JFrame {
JFrame f;
p61(){
f=new JFrame();
[Link](JFrame.EXIT_ON_CLOSE);
[Link](300, 200);
String[] cities = {"Solapur", "Mumbai", "Pune", "Bangalore"};
JComboBox<String> cityComboBox = new JComboBox<>(cities);
JLabel cityLabel = new JLabel("Select a city");
[Link](new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String selectedCity = (String) [Link]();
[Link]("You are in " + selectedCity);
});
[Link](new [Link]());
[Link](cityComboBox);
[Link](cityLabel);
// Make the frame visible
[Link](true);
public static void main(String[] args) {
new p61();
}
OUTPUT:
import [Link].*;
import [Link].*;
public class p62 extends JFrame {
JFrame f;
p62(){
f=new JFrame();
[Link](JFrame.EXIT_ON_CLOSE);
[Link](300, 200);
String[] states = {"Maharashtra", "Karnataka", "Gujarat", "Madhya
Pradesh","Rajasthan","Kerala","Telangana"};
JComboBox<String> cityComboBox = new JComboBox<>(states);
JLabel cityLabel = new JLabel("Select a State");
[Link](new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String selectedCity = (String) [Link]();
[Link]("You are in " + selectedCity);
});
[Link](new [Link]());
[Link](cityComboBox);
[Link](cityLabel);
// Make the frame visible
[Link](true);
public static void main(String[] args) {
new p62();
}
OUTPUT:
import [Link].*;
public class p63 {
public static void main(String[] args) {
// Create a new JFrame
JFrame frame = new JFrame("JScrollPane Example");
[Link](JFrame.EXIT_ON_CLOSE);
[Link](400, 300);
// Create a JPanel with a vertical BoxLayout
JPanel panel = new JPanel();
[Link](new BoxLayout(panel, BoxLayout.Y_AXIS));
// Add multiple labels to the panel
for (int i = 1; i <= 50; i++) {
[Link](new JLabel("Label " + i));
// Create a JScrollPane and add the panel to it
JScrollPane scrollPane = new JScrollPane(panel);
// Add the JScrollPane to the frame
[Link](scrollPane);
// Make the frame visible
[Link](true);
OUTPUT: