The following illustrates use of ItemListener with AWT CheckboxMenuItem.
CheckboxMenuItemEvent(): Code illustrating use of ItemListener with AWT CheckboxMenuItem is written here.
A CheckboxMenuItem is a menu item that can be checked as you see in Notepad > Format > Wordwrap.
Next: Using ItemListener for AWT RadioButton
import java.awt.*;
import java.awt.event.*;
class CheckboxMenuItemEvent extends Frame
{
CheckboxMenuItem c;
MenuBar mb;
Menu m;
public CheckboxMenuItemEvent()
{
createAndShowGUI();
}
private void createAndShowGUI()
{
setTitle("CheckboxMenuItem with ItemListener demo");
// Create menubar and menu
mb=new MenuBar();
m=new Menu("Menu");
// Create simple CheckboxMenuItem
c=new CheckboxMenuItem("Check me");
// Add ItemListener
c.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent ie)
{
// Change frame title
setTitle("You "+(c.getState()?"checked":"unchecked")+".");
}
});
// Add checkboxmenuitem,menu and MenuBar
m.add(c);
mb.add(m);
setMenuBar(mb);
setSize(400,400);
setVisible(true);
}
public static void main(String args[])
{
new CheckboxMenuItemEvent();
}
}
CheckboxMenuItemEvent(): Code illustrating use of ItemListener with AWT CheckboxMenuItem is written here.
A CheckboxMenuItem is a menu item that can be checked as you see in Notepad > Format > Wordwrap.
No comments:
Post a Comment