i am trying to get the combo-box when a option is selected it does something like print some text but i dont know how to do it after hours of trying to figure it out.i know it has something to do with the event listener. New to java. Any help is appreciated.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JComboBox;
public class Frame extends JFrame
{
//Instance Variables.
private static final int FRAME_WIDTH = 500;
private static final int FRAME_HEIGHT = 400;
public Frame()
{
Venue1();
setSize(FRAME_WIDTH, FRAME_HEIGHT);
}
private void Venue1()
{
//String [] Venues = {"Elvis","Gorillaz", "Imagine Dragons","Michael Jackson"};
JComboBox DropMenu = new JComboBox();
DropMenu.addItem("Elvis");
DropMenu.addItem("Gorillaz");
DropMenu.addItem("Imagine Dragons");
DropMenu.addItem("Michael Jackson");
DropMenu.setEditable(false);
DropMenu.setVisible(true);
JPanel panel = new JPanel();
JLabel label = new JLabel("Pick a venue");
add(panel);
panel.add(label);
panel.add(DropMenu);
ActionListener listener = new listener();
DropMenu.addActionListener(listener);
}//End of Venue Method.
}//End of class.
//Button Listeners
class listener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
}
}
enter code here