-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMini Notepad.java
More file actions
54 lines (49 loc) · 1.64 KB
/
Copy pathMini Notepad.java
File metadata and controls
54 lines (49 loc) · 1.64 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
});
// Save
save.addActionListener(e -> {
JFileChooser fileChooser = new JFileChooser();
int option = fileChooser.showSaveDialog(frame);
if (option == JFileChooser.APPROVE_OPTION) {
File files = fileChooser.getSelectedFile();
try {
FileWriter writer = new FileWriter(files);
writer.write(ta.getText());
writer.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
// Cut
cut.addActionListener(e -> {
ta.cut();
});
// Copy
copy.addActionListener(e -> {
ta.copy();
});
// Paste
paste.addActionListener(e -> {
ta.paste();
});
// Font Color
textColor.addActionListener(e -> {
Color color = JColorChooser.showDialog(frame, "Choose Text Color", Color.BLACK);
if (color != null) {
ta.setForeground(color);
}
});
// Font Size
fontSize.addActionListener(e -> {
String size = JOptionPane.showInputDialog(frame, "Enter Font Size:");
try {
int fontSizeValue = Integer.parseInt(size);
Font currentFont = ta.getFont();
Font newFont = new Font(currentFont.getName(), currentFont.getStyle(), fontSizeValue);
ta.setFont(newFont);
} catch (Exception ex) {
JOptionPane.showMessageDialog(frame, "Invalid Input!");
}
});
}
}