forked from Ashish8104/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuDemo.java
More file actions
53 lines (49 loc) · 1.19 KB
/
MenuDemo.java
File metadata and controls
53 lines (49 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.awt.*;
import java.awt.event.*;
class MenuDemo implements ActionListener
{
Frame f;MenuBar mb;Menu m1,m2,m3;
MenuItem nw,opn,sve,ext,ct,cpy,pst;
CheckboxMenuItem bld,itlc;
public MenuDemo()
{
f=new Frame();f.setSize(400,400);
mb=new MenuBar();
m1=new Menu("File");
m2=new Menu("Edit");
m3=new Menu("Others");
nw=new MenuItem("New");
opn=new MenuItem("Open");
sve=new MenuItem("Save");
ext=new MenuItem("Exit");
ct=new MenuItem("Cut");
cpy=new MenuItem("Copy");
pst=new MenuItem("Paste");
nw.addActionListener(this);
opn.addActionListener(this);
sve.addActionListener(this);
ext.addActionListener(this);
ct.addActionListener(this);
cpy.addActionListener(this);
pst.addActionListener(this);
bld=new CheckboxMenuItem("Bold");
itlc=new CheckboxMenuItem("Italic");
itlc.setState(true);
m3.add(ct);m3.add(cpy);m3.add(pst);
m2.add(bld);m2.add(itlc);m2.addSeparator();m2.add(m3);
m1.add(nw);m1.add(opn);m1.add(sve);m1.addSeparator();
m1.add(ext);
mb.add(m1);mb.add(m2);mb.add(m3);
f.setMenuBar(mb);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String str=e.getActionCommand();
System.out.println(str+"was clicked");
}
public static void main(String args[])
{
MenuDemo d=new MenuDemo();
}
}