0% found this document useful (0 votes)
18 views1 page

Java Practical 18

The document is a Java program that creates a graphical user interface (GUI) for selecting a city from a dropdown menu. It uses Swing components, including a JComboBox for city selection and a JLabel to display the selected city. The program initializes with 'Mumbai' as the default city and updates the label when a different city is selected.

Uploaded by

londheprerana72
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views1 page

Java Practical 18

The document is a Java program that creates a graphical user interface (GUI) for selecting a city from a dropdown menu. It uses Swing components, including a JComboBox for city selection and a JLabel to display the selected city. The program initializes with 'Mumbai' as the default city and updates the label when a different city is selected.

Uploaded by

londheprerana72
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Practical 18:Q4

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class CitySelection extends JFrame
{
JComboBox<String> cityComboBox;
JLabel label;
public CitySelection()
{
setTitle("City Selector");
setSize(400, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
String[] cities = {"Mumbai", "Solapur", "Pune", "Banglore"};
cityComboBox = new JComboBox<>(cities);
label = new JLabel("You are in Mumbai");
cityComboBox.addActionListener(new ActionListener());
{
public void actionPerformed(ActionEvent e)
{
label.setText("You are in " + cityComboBox.getSelectedItem());
}
}
add(cityComboBox);
add(label);
setVisible(true);
}
public static void main(String[] args)
{
new CitySelection();
}
}

You might also like