-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotePad.java
330 lines (269 loc) · 11.6 KB
/
NotePad.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
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
import javafx.scene.text.FontWeight;
import java.awt.Color;
import javax.swing.*;
import java.awt.*;
import java.awt.Font;
import java.awt.event.*;
import java.util.Scanner;
import java.io.*;
public class NotePad extends JFrame implements ActionListener {
private TextArea textArea = new TextArea("",0,0, TextArea.SCROLLBARS_VERTICAL_ONLY);
//private TextArea textArea2 = new TextArea("", 0,0, TextArea.SCROLLBARS_VERTICAL_ONLY);
JTextArea txt = new JTextArea();
private MenuBar menuBar = new MenuBar();
private Menu file = new Menu();
private MenuItem openFile = new MenuItem();
private MenuItem saveFile = new MenuItem();
private MenuItem close = new MenuItem();
private MenuItem newFile = new MenuItem();
private Menu fonts = new Menu();
private MenuItem BoldFont = new MenuItem();
private MenuItem ItalicFont = new MenuItem();
private MenuItem NormalFont = new MenuItem();
private Menu size = new Menu();
private MenuItem size14 = new MenuItem();
private MenuItem size16 = new MenuItem();
private MenuItem size18 = new MenuItem();
private MenuItem size20 = new MenuItem();
private Menu FontStyle = new Menu();
private MenuItem s1 = new MenuItem();
private MenuItem s2 = new MenuItem();
private MenuItem s3 = new MenuItem();
private MenuItem s4 = new MenuItem();
private MenuItem s5 = new MenuItem();
private Menu About = new Menu();
private MenuItem team = new MenuItem();
private MenuItem outline = new MenuItem();
private Menu OpenLists = new Menu();
private MenuItem todo = new MenuItem();
public NotePad() {
this.setSize(700, 500);
this.setTitle("Notepad");
setDefaultCloseOperation(EXIT_ON_CLOSE);
this.textArea.setFont(new Font("Century Gothic", Font.PLAIN, 16));
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(textArea);
this.setMenuBar(this.menuBar);
////////////////////////////////////////////////////////////////////////
this.menuBar.add(this.file);
this.file.setLabel("File");
this.newFile.setLabel("New");
this.newFile.addActionListener(this);
this.newFile.setShortcut(new MenuShortcut(KeyEvent.VK_N, false));
this.file.add(this.newFile);
this.openFile.setLabel("Open");
this.openFile.addActionListener(this);
this.openFile.setShortcut(new MenuShortcut(KeyEvent.VK_O, false));
this.file.add(this.openFile);
this.saveFile.setLabel("Save");
this.saveFile.addActionListener(this);
this.saveFile.setShortcut(new MenuShortcut(KeyEvent.VK_S, false));
this.file.add(this.saveFile);
this.close.setLabel("Close");
this.close.setShortcut(new MenuShortcut(KeyEvent.VK_F4, false));
this.close.addActionListener(this);
this.file.add(this.close);
/////////////////////////////////////////////////////////////////////////
this.menuBar.add(fonts);
this.fonts.setLabel("Font");
this.BoldFont.setLabel("Bold");
this.BoldFont.setShortcut(new MenuShortcut(KeyEvent.VK_B, false));
this.BoldFont.addActionListener(this);
this.fonts.add(this.BoldFont);
this.ItalicFont.setLabel("Italic");
this.ItalicFont.setShortcut(new MenuShortcut(KeyEvent.VK_I, false));
this.ItalicFont.addActionListener(this);
this.fonts.add(this.ItalicFont);
this.NormalFont.setLabel("Regular");
this.NormalFont.setShortcut(new MenuShortcut(KeyEvent.VK_N, false));
this.NormalFont.addActionListener(this);
this.fonts.add(this.NormalFont);
//////////////////////////////////////////////////////////////////////////
this.menuBar.add(size);
this.size.setLabel("Size");
this.size14.setLabel("14");
this.size14.addActionListener(this);
this.size.add(this.size14);
this.size16.setLabel("16");
this.size16.addActionListener(this);
this.size.add(this.size16);
this.size18.setLabel("18");
this.size18.addActionListener(this);
this.size.add(this.size18);
this.size20.setLabel("20");
this.size20.addActionListener(this);
this.size.add(this.size20);
//////////////////////////////////////////////////////////////////////////
this.menuBar.add(FontStyle);
this.FontStyle.setLabel("Font Style");
this.s1.setLabel("Century Gothic");
this.s1.addActionListener(this);
this.FontStyle.add(this.s1);
this.s2.setLabel("Arial");
this.s2.addActionListener(this);
this.FontStyle.add(this.s2);
this.s3.setLabel("Comic");
this.s3.addActionListener(this);
this.FontStyle.add(this.s3);
this.s4.setLabel("Freestyle Script");
this.s4.addActionListener(this);
this.FontStyle.add(this.s4);
this.s5.setLabel("Papyrus");
this.s5.addActionListener(this);
this.FontStyle.add(this.s5);
//////////////////////////////////////////////////////////////////////////////
this.menuBar.add(About);
this.About.setLabel("About");
this.team.setLabel("Team");
this.team.addActionListener(this);
this.About.add(this.team);
this.outline.setLabel("Outline");
this.outline.addActionListener(this);
this.About.add(this.outline);
this.menuBar.add(OpenLists);
this.OpenLists.setLabel("To-Do Lists");
this.todo.setLabel("Open To-Do List");
this.todo.addActionListener(this);
this.OpenLists.add(this.todo);
}
public void actionPerformed (ActionEvent e) {
if (e.getSource() == this.close)
{
this.dispose();
}
else if (e.getSource() == this.todo) {
String[] args = {"NotePad"} ;
CheckBoxJList.main(args);
}
else if (e.getSource() == this.s1)
{
this.textArea.setFont(new Font("Century Gothic", Font.PLAIN, 16));
}
else if (e.getSource() == this.s2)
{
this.textArea.setFont(new Font("Arial", Font.PLAIN, 16));
}
else if (e.getSource() == this.s3)
{
this.textArea.setFont(new Font("Comic sans MS", Font.PLAIN, 16));
}
else if (e.getSource() == this.s4)
{
this.textArea.setFont(new Font("Freestyle Script", Font.PLAIN, 16));
}
else if (e.getSource() == this.s5)
{
this.textArea.setFont(new Font("Papyrus", Font.PLAIN, 16));
}
else if (e.getSource() == this.NormalFont)
{
this.textArea.setFont(new Font("Century Gothic", Font.PLAIN, 16));
}
else if(e.getSource() == this.team)
{
JFrame aboutWindow = new JFrame("Team ");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(null);
txt.setBounds(3, 3, 300, 100);
add(txt);
Font font = new Font("Papyrus", Font.BOLD, 18);
txt.setFont(font);
txt.setForeground(Color.BLUE);
txt.setText("Ankita Christine Victor\n" +
"Rahul Rachuri\n" +
"Anup Deshmukh\n\n\n\n" );
aboutWindow.getContentPane().setLayout(new BorderLayout());
aboutWindow.setSize(400,300);
aboutWindow.getContentPane().add(txt);
aboutWindow.setVisible(true);
}
else if(e.getSource() == this.outline)
{
JFrame aboutWindow2 = new JFrame("Application ");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(null);
txt.setBounds(3, 3, 300, 100);
add(txt);
Font font = new Font("Calibri", Font.BOLD, 16);
txt.setFont(font);
txt.setForeground(Color.BLACK);
txt.setText("Welcome to our Notepad!\n\n 1] You can create notes or edit existing ones.\n 2] Use CTRL+O to choose the file to be opened and CTRL+N to open a new file.\n 3] Once you are done with your file press CTRL+S or use the dropdown menu to select 'Save' and choose the location to save your file.\n 4] When you are editing, you increase or decrease the font size used in the document or change the font style from the options provided in their respective dropdown menus.\n\n\n We plan on taking this further in the future by integrating it with our To-Do List application and possibly integrating it with a cloud service and providing more functionality and customisation to the user.\n\n Thank you for using our product! \n");
aboutWindow2.getContentPane().setLayout(new BorderLayout());
aboutWindow2.setSize(1500,300);
aboutWindow2.getContentPane().add(txt);
aboutWindow2.setVisible(true);
}
else if (e.getSource() == this.ItalicFont)
{
this.textArea.setFont(new Font("Italic", Font.ITALIC, 16));
}
else if (e.getSource() == this.NormalFont)
{
this.textArea.setFont(new Font("Century Gothic", Font.PLAIN, 16));
}
else if (e.getSource() == this.size14)
{
Font font = this.textArea.getFont();
String name = font.getName();
this.textArea.setFont(new Font(name, Font.PLAIN, 14));
}
else if (e.getSource() == this.size16)
{
Font font = this.textArea.getFont();
String name = font.getName();
this.textArea.setFont(new Font(name, Font.PLAIN, 16));
}
else if (e.getSource() == this.size18)
{
Font font = this.textArea.getFont();
String name = font.getName();
this.textArea.setFont(new Font(name, Font.PLAIN, 18));
}
else if (e.getSource() == this.size20)
{
Font font = this.textArea.getFont();
String name = font.getName();
this.textArea.setFont(new Font(name, Font.PLAIN, 20));
}
else if (e.getSource() == this.BoldFont) {
Font font = this.textArea.getFont();
String name = font.getName();
this.textArea.setFont(new Font(name, Font.BOLD, 16));
}
else if (e.getSource() == this.newFile) {
NotePad NotePad2 = new NotePad();
NotePad2.setVisible(true);
}
else if (e.getSource() == this.openFile) {
JFileChooser open = new JFileChooser();
int option = open.showOpenDialog(this);
if (option == JFileChooser.APPROVE_OPTION) {
this.textArea.setText("");
try {
Scanner scan = new Scanner(new FileReader(open.getSelectedFile().getPath()));
while (scan.hasNext())
this.textArea.append(scan.nextLine() + "\n");
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
}
else if (e.getSource() == this.saveFile) {
JFileChooser save = new JFileChooser();
int option = save.showSaveDialog(this);
if (option == JFileChooser.APPROVE_OPTION) {
try {
BufferedWriter out = new BufferedWriter(new FileWriter(save.getSelectedFile().getPath()));
out.write(this.textArea.getText());
out.close();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
}
}
public static void main(String[] args) {
NotePad app = new NotePad();
app.setVisible(true);
}
}