MenuTest in Java Program
MenuTest in Java Program
import java.awt.event.*;
import java.Swing.*;
import javax.Swing.event.*;
public classMenuTest
{
public Static void main(String[] aegs)
{
MenuFrame frame=new MenuFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class MenuFrame extends JFrame
{
public MenuFrame()
{
setTitle(300,200);
JMenu fileMenu=new JMenu("File");
JMenuItem newItem=fileMenu.add(new TestAction("new"));
newItem setMnemonic('N');
JMenuItem openItem=fileMenu.add(new TestAction("open"));
openItem.setAcclerator(KeyStroke.getKeyStroke(KeyEvent.vk_0,InputEvent.CTRL_MASK));
JCheckBox MenuItem readonlyItem=new JCheckBoxMenuItem("Read-only");
ButtonGroup group=new ButtonGroup();
JRadioButtonMenuItem insertItem=new JRadioButtonMenuItem("Insert");
insertItem.setSelected(true);
JRadioButtonMenuItem overtypeItem=new RadioButtonMenuItem("overtype");
group.add(insertItem);
group.add(overtypeItem);
JMenu optionMenu=new JMenu("Options");
OptionsMenu.add(readOnlyItem);
OptionsMenu.addSeperator();
OptionMenu.add(insertItem);
fileMenu.add(Option Menu);
fileMenu.addSeperator();
fileMenu.add(newAbstractAction("EXIT");
{
public void actionPerformed(ActionEvent event)
{
System.exit(0);
}
});
Action cutAction=new TestAction("cut");
cutAction.putValue(Action.sMALL_ICON,newImageIcon("cut.gif"));
JMenuBar menuBar=new JMenuBar();
setMenuBar(menuBar);
menuBar.add(fileMenu);
popup=new JPopupMenu();
Popup.add(cutAction);
Popup.add(Copy Action);
getContentPane().addMouseListner(new MouseAdaprer()
{
public void mousePressed(MOuseEvent event)
{
if(event is PopupTrigger())
Popup.show(event.getComponent() event.getX(),event.getY());
}
public void mouseReleased(MouseEvent event)
{
if(event.isPopup Trigger())
Popup.show(event.getComponent();
event.getX(),event.getY());
}
});
}
private JPopupMenu popup;
}
0 coment�rios:
Post a Comment