-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuBarSwings.java
78 lines (67 loc) · 1.73 KB
/
MenuBarSwings.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
71
72
73
74
75
76
77
78
import javax.swing.*;
import java.awt.event.*;
public class MenuBarSwings extends JFrame implements ActionListener{
JFrame f;
JMenuBar mb;
JMenu file,edit,help;
JMenuItem cut,copy,paste,selectAll,open,save,newF,close,feedback,exit;
JTextArea ta;
MenuBarSwings()
{
super("NOTEPAD using GUI");
f=new JFrame();
mb=new JMenuBar();
f.add(mb);
file=new JMenu("File");
edit= new JMenu("Edit");
help=new JMenu("Help");
mb.add(file);
mb.add(edit);
mb.add(help);
cut=new JMenuItem("Cut");
copy=new JMenuItem("Copy");
paste=new JMenuItem("Paste");
selectAll=new JMenuItem("Select All");
edit.add(cut);
edit.add(copy);
edit.add(paste);
edit.add(selectAll);
cut.addActionListener(this);
copy.addActionListener(this);
paste.addActionListener(this);
selectAll.addActionListener(this);
open=new JMenuItem("Open File");
save=new JMenuItem("Save File");
newF=new JMenuItem("New File");
close=new JMenuItem("Close File");
file.add(open);
file.add(save);
file.add(newF);
file.add(close);
feedback=new JMenuItem("Feedback");
exit=new JMenuItem("Exit");
help.add(feedback);
help.add(exit);
ta=new JTextArea();
ta.setBounds(10,10,580,380);
f.add(ta);
f.setJMenuBar(mb);
f.setLayout(null);
f.setLocation(300,100);
f.setSize(600,450);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==cut)
ta.cut();
if(e.getSource()==copy)
ta.copy();
if(e.getSource()==paste)
ta.paste();
if(e.getSource()==selectAll)
ta.selectAll();
}
public static void main(String [] args){
new MenuBarSwings();
}
}