skip to main |
skip to sidebar
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="men1" width=200 height=200>
</applet>
*/
class MenuFrame extends Frame
{
String msg="";
CheckboxMenuItem debug,test;
MenuFrame(String title)
{
super(title);
MenuBar mbar = new MenuBar();
setMenuBar(mbar);
Menu file =new Menu("file");
MenuItem item1,item2,item3,item4,item5;
file.add(item1 = new MenuItem("New..."));
file.add(item2 = new MenuItem("Open..."));
file.add(item3 = new MenuItem("Close..."));
file.add(item4 = new MenuItem("-"));
file.add(item5 = new MenuItem("quit..."));
mbar.add(file);
Menu edit =new Menu("edit");
MenuItem item6,item7,item8,item9;
edit.add(item6 = new MenuItem("cut"));
edit.add(item7 = new MenuItem("copy"));
edit.add(item8 = new MenuItem("paste"));
edit.add(item9 = new MenuItem("-"));
Menu sub = new Menu("special");
MenuItem item10,item11,item12;
sub.add(item10 = new MenuItem("First"));
sub.add(item11 = new MenuItem("Second"));
sub.add(item12 = new MenuItem("Third"));
edit.add(sub);
debug = new CheckboxMenuItem("debug");
edit.add(debug);
test = new CheckboxMenuItem("testing");
edit.add(test);
mbar.add(edit);
MyMenuHandler handler = new MyMenuHandler(this);
item1.addActionListener(handler);
item2.addActionListener(handler);
item3.addActionListener(handler);
item4.addActionListener(handler);
item5.addActionListener(handler);
item6.addActionListener(handler);
item7.addActionListener(handler);
item8.addActionListener(handler);
item9.addActionListener(handler);
item10.addActionListener(handler);
item11.addActionListener(handler);
item12.addActionListener(handler);
debug.addItemListener(handler); ;
test.addItemListener(handler)
MyWindowAdapteradapter=new MyWindowAdapter(this);
addWindowListener(adapter);
}
public void paint(Graphics g)
{
g.drawString(msg,10,200);
if(debug.getState())
g.drawString("Debug is on.",10,220);
else
g.drawString("Debug is off.",10,220);
g.drawString(msg,10,200);
if(test.getState())
g.drawString("Testing is on.",10,240);
else
g.drawString("Testing is off.",10,240);
}
}
class MyWindowAdapter extends WindowAdapter
{
MenuFrame menuFrame;
public MyWindowAdapter(MenuFrame menuframe)
{
this.menuFrame =menuFrame;
}
public void windowClosing(WindowEvent we)
{
menuFrame.setVisible(false);
}
}
class MyMenuHandler implements ActionListener,ItemListener
{
MenuFrame menuFrame;
public MyMenuHandler(MenuFrame menuFrame)
{
this.menuFrame = menuFrame;
}
public void actionPerformed(ActionEvent ae)
{
String msg="You Selected : ";
String arg =(String)ae.getActionCommand();
if(arg.equals("New..."))
msg += "New.";
else if(arg.equals("Open..."))
msg += "Open.";
else if(arg.equals("Close..."))
msg += "Close.";
else if(arg.equals("Quit..."))
msg += "Quit.";
else if(arg.equals("Edit"))
msg += "Edit.";
else if(arg.equals("copy"))
msg += "copy.";
else if(arg.equals("paste"))
msg += "paste.";
else if(arg.equals("First"))
msg += "First.";
else if(arg.equals("Second"))
msg += "Second.";
else if(arg.equals("Third"))
msg += "Third.";
else if(arg.equals("Debug"))
msg += "Debug.";
else if(arg.equals("Testing"))
msg += "Testing.";
menuFrame.msg =msg;
menuFrame.repaint();
}
public void itemStateChanged(ItemEvent ie)
{
menuFrame.repaint();
}
}
public class men1 extends Applet
{
Frame f;
public void init()
{
f=new MenuFrame("menu");
int width = Integer.parseInt(getParameter("width"));
int height = Integer.parseInt(getParameter("height"));
setSize(new Dimension (width,height));
f.setSize(width,height);
f.setVisible(true);
}
public void start()
{
f.setVisible(true);
}
public void stop()
{
f.setVisible(false);
}
}
OUTPUT:
0 comments:
Post a Comment