-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotepad.java
More file actions
266 lines (185 loc) · 6.18 KB
/
Notepad.java
File metadata and controls
266 lines (185 loc) · 6.18 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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
import javax.swing.*;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Notepad {
public void Create(){
JFrame jf=new JFrame("Notepad");
jf.setSize(500,500);
JTextArea jt=new JTextArea("Write here ");
jt.setBounds(10,20,700,700);
jt.setBackground(Color.white);
jf.setLayout(null);
jf.setVisible(true);
JMenuBar jm=new JMenuBar();
JMenuItem jit=new JMenuItem();
JMenu file,edit,view,setting;
// JPopupMenu back,cut,copy;
// JPopupMenu jp=new JPopupMenu();
//
// back=new JPopupMenu("back");
//
// cut=new JPopupMenu("cut");
//
// copy=new JPopupMenu("copy");
// back.addActionListener(new ActionListener() {
// @Override
// actionPerformed(ActionEvent e){} {
// int a = JOptionPane.showConirmDialog(jf, "You Want to back");
// if (a == JOptionPane.YES_OPTION) {
// jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE);
// }
// }
// });
// cut.addPopupMenuListener(new PopupMenuListener() {
// @Override
// public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
//
// if(e.getSource()==cut){
// jt.cut();
// }
//
//
// }
//
// });
// copy.addPopupMenuListener(new PopupMenuListener() {
// @Override
// public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
// if(e.getSource()==copy){
// jt.copy();
// }
// }
//
//
// });
//
JMenuItem past,save,cut,copy,exit,zoom,status;
cut= new JMenuItem("cut");
copy =new JMenuItem("copy");
save=new JMenuItem("save");
past=new JMenuItem("past");
exit=new JMenuItem("Exit");
zoom=new JMenuItem("Zoom");
status=new JMenuItem("status");
//zoom =new JMenuItem("Zoom");
cut.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==cut){
jt.cut();
}
}
});
copy.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource()==copy) {
jt.copy();
}
}
});
past.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==past){
jt.paste();
}
}
});
exit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int a= JOptionPane.showConfirmDialog(jf,"You Want to exit");
if(a==JOptionPane.YES_OPTION){
jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE);
}
}
});
zoom.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==zoom){
jt.show();
}
}
});
status.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Read Given Text ");
}
});
// zoom.addActionListener(new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// if(e.getSource()==zoom){
// jt.zo
// }
// }
// });
file =new JMenu("file");
file.add(save);
file.add(exit);
edit =new JMenu("Edit");
edit.add(cut);
view =new JMenu("View");
view.add(zoom);
view.add(status);
setting =new JMenu("Setting ");
edit.add(copy);
// edit.add(zoom);
edit.add(past);
jm.add(file);
jm.add(edit);
jm.add(view);
jm.add(setting);
jf.setJMenuBar(jm);
jf.add(jm);
jf.add(jit);
jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
jf.add(jt);
jf.add(jm);
jf.add(jit);
jt.addAncestorListener(new AncestorListener() {
@Override
public void ancestorAdded(AncestorEvent event) {
System.out.println("text area ");
}
@Override
public void ancestorRemoved(AncestorEvent event) {
System.out.println("Romive ");
}
@Override
public void ancestorMoved(AncestorEvent event) {
}
});
jf.addWindowListener(new WindowAdapter() {
@Override
public void windowActivated(WindowEvent e) {
super.windowActivated(e);
System.out.println("Window Activated");
}
@Override
public void windowDeactivated(WindowEvent e){
super.windowDeactivated(e);
System.out.println("Window Diactivated");
}
@Override
public void windowClosing(WindowEvent e){
super.windowClosing(e);
System.out.println("Window is Closing ");
}
});
}
public static void main(String[] args) {
Notepad np=new Notepad();
np.Create();
}
}