Choice in Java AWT


Choice class is part of Java Abstract Window Toolkit(AWT). The Choice class presents a pop- up menu for the user, the user may select an item from the popup menu.

Source Code

package awtDemo;
 
import java.awt.*;
import java.awt.event.*;
 
//Choice in Java AWT
class MyApp extends Frame{
 
 
	Choice c;
	Button btn;
	Label lbl;
 
	public MyApp() {
		super("Tutor Joes");
		setSize(1000, 600);// w,h
		setLayout(null);
		setVisible(true);
 
		c = new Choice();
		c.setBounds(10, 50, 100, 100);
 
		c.add("C");
		c.add("C++");
		c.add("Java");
		c.add("PHP");
		c.add("Android");
 
		btn = new Button("Show Details");
		btn.setBounds(120, 50, 100, 20);
		btn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String data = "Programming language Selected: " + c.getItem(c.getSelectedIndex());
				lbl.setText(data);
			}
		});
 
 
		lbl = new Label("Empty Label");
		lbl.setBounds(10, 70, 300, 30);
 
		add(c);
		add(btn);
		add(lbl);
		// Close Button Code
		this.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent we) {
				System.exit(0);
			}
		});
	}
 
}
 
public class app {
	public static void main(String[] args) {
		MyApp frm = new MyApp();
	}
 
}
 
To download raw file Click Here

Basic Programs



Learn All in Tamil © Designed & Developed By Tutor Joes