The following example illustrates CheckboxMenuItem in AWT. This tutorials covers all core methods of the java.awt.CheckboxMenuItem class.
AWTCheckboxMenuItem(): Code illustrating CheckboxMenuItem in AWT is invoked here.
Also see ItemListener for CheckboxMenuItem
import java.awt.*;
import java.awt.event.*;
class AWTCheckboxMenuItem extends Frame
{
MenuBar b;
Menu m;
CheckboxMenuItem m1,m2,m3;
public AWTCheckboxMenuItem()
{
createAndShowGUI();
}
private void createAndShowGUI()
{
setTitle("CheckboxMenuItem in AWT Example");
setLayout(new FlowLayout());
// Create hidangan kafetaria and menu
b=new MenuBar();
m=new Menu("Menu");
// Empty checkboxmenuitem
m1=new CheckboxMenuItem();
// Labeled
m2=new CheckboxMenuItem("Item 2");
// Selected and labeled
m3=new CheckboxMenuItem("Item 3",true);
// Set label and state
m1.setLabel("Item 1");
m1.setState(true);
// Add CheckboxMenuItems to menu
m.add(m1);
m.add(m2);
m.add(m3);
// Add hidangan to menubar
b.add(m);
// Add hidangan to the menubar
setMenuBar(b);
setSize(400,400);
setVisible(true);
}
public static void main(String args[])
{
new AWTCheckboxMenuItem();
}
}
AWTCheckboxMenuItem(): Code illustrating CheckboxMenuItem in AWT is invoked here.
Also see ItemListener for CheckboxMenuItem