forked from mohammedabdulbari/Java-SE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MenuDemo.java
70 lines (52 loc) · 1.56 KB
/
MenuDemo.java
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package menudemo;
import java.awt.*;
import java.awt.event.*;
class MyFrame extends Frame
{
Menu file,sub;
MenuItem open,save,close,closeall;
CheckboxMenuItem auto;
TextField tf;
MyFrame()
{
super("Menu Demo");
open=new MenuItem("Open");
save=new MenuItem("Save");
close=new MenuItem("Close");
closeall=new MenuItem("Close All");
auto=new CheckboxMenuItem("Auto Save");
file=new Menu("File");
sub=new Menu("Close");
file.add(open);
file.add(save);
file.add(sub);
file.add(auto);
sub.add(close);
sub.add(closeall);
MenuBar mb=new MenuBar();
mb.add(file);
setMenuBar(mb);
tf=new TextField(20);
setLayout(new FlowLayout());
add(tf);
open.addActionListener((ActionEvent ae)->tf.setText("Open"));
save.addActionListener((ActionEvent ae)->tf.setText("Save"));
close.addActionListener((ActionEvent ae)->tf.setText("Close"));
closeall.addActionListener((ActionEvent ae)->tf.setText("Close All"));
auto.addItemListener((ItemEvent ie)->{
if(auto.getState())
tf.setText("Auto On");
else
tf.setText("Auto Off");
});
}
}
public class MenuDemo
{
public static void main(String[] args)
{
MyFrame f=new MyFrame();
f.setSize(500,500);
f.setVisible(true);
}
}