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
Previous: Creating Menus and MenuItems in AWT
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 menu bar 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 menu to menubar
b.add(m);
// Add menu 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
Previous: Creating Menus and MenuItems in AWT
No comments:
Post a Comment