-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.java
More file actions
192 lines (171 loc) · 8.29 KB
/
GUI.java
File metadata and controls
192 lines (171 loc) · 8.29 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
import javax.swing.*;
public class GUI {
public static void main(String[] args) {
JFrame frame = new JFrame("Notetaking Tool");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 500);
frame.setLayout(null);
JPanel panel = new JPanel(null);
panel.setBounds(0, 0, 600, 500);
panel.setBackground(new java.awt.Color(245, 245, 255));
JLabel titleLabel = new JLabel("Note Title:");
titleLabel.setBounds(30, 20, 80, 25);
titleLabel.setFont(new java.awt.Font("Segoe UI", java.awt.Font.PLAIN, 14));
JTextField titleField = new JTextField();
titleField.setBounds(120, 20, 200, 28);
titleField.setFont(new java.awt.Font("Segoe UI", java.awt.Font.PLAIN, 14));
titleField.setBackground(new java.awt.Color(255, 255, 240));
titleField.setBorder(javax.swing.BorderFactory.createCompoundBorder(
javax.swing.BorderFactory.createLineBorder(new java.awt.Color(120, 120, 200), 2),
javax.swing.BorderFactory.createEmptyBorder(4, 8, 4, 8)
));
JLabel notesListLabel = new JLabel("Saved Notes:");
notesListLabel.setBounds(350, 20, 100, 25);
notesListLabel.setFont(new java.awt.Font("Segoe UI", java.awt.Font.PLAIN, 14));
javax.swing.DefaultListModel<String> listModel = new javax.swing.DefaultListModel<>();
JList<String> notesList = new JList<>(listModel);
JScrollPane listScroll = new JScrollPane(notesList);
listScroll.setBounds(350, 50, 200, 300);
JLabel contentLabel = new JLabel("Note Content:");
contentLabel.setBounds(30, 60, 120, 25);
contentLabel.setFont(new java.awt.Font("Segoe UI", java.awt.Font.PLAIN, 14));
JTextArea noteArea = new JTextArea();
noteArea.setFont(new java.awt.Font("Segoe UI", java.awt.Font.PLAIN, 15));
noteArea.setLineWrap(true);
noteArea.setWrapStyleWord(true);
noteArea.setBackground(new java.awt.Color(255, 255, 240));
noteArea.setBorder(javax.swing.BorderFactory.createCompoundBorder(
javax.swing.BorderFactory.createLineBorder(new java.awt.Color(120, 120, 200), 2),
javax.swing.BorderFactory.createEmptyBorder(8, 8, 8, 8)
));
JScrollPane areaScroll = new JScrollPane(noteArea);
areaScroll.setBounds(30, 90, 290, 260);
JButton saveButton = new JButton("Save Note");
saveButton.setBounds(30, 370, 110, 32);
saveButton.setBackground(new java.awt.Color(120, 120, 200));
saveButton.setForeground(java.awt.Color.WHITE);
saveButton.setFocusPainted(false);
saveButton.setFont(new java.awt.Font("Segoe UI", java.awt.Font.BOLD, 14));
saveButton.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(80, 80, 160), 2));
saveButton.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseEntered(java.awt.event.MouseEvent evt) {
saveButton.setBackground(new java.awt.Color(80, 80, 160));
}
@Override
public void mouseExited(java.awt.event.MouseEvent evt) {
saveButton.setBackground(new java.awt.Color(120, 120, 200));
}
});
JButton clearButton = new JButton("Clear");
clearButton.setBounds(150, 370, 80, 32);
clearButton.setBackground(new java.awt.Color(200, 120, 120));
clearButton.setForeground(java.awt.Color.WHITE);
clearButton.setFocusPainted(false);
clearButton.setFont(new java.awt.Font("Segoe UI", java.awt.Font.BOLD, 14));
clearButton.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(160, 80, 80), 2));
clearButton.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseEntered(java.awt.event.MouseEvent evt) {
clearButton.setBackground(new java.awt.Color(160, 80, 80));
}
@Override
public void mouseExited(java.awt.event.MouseEvent evt) {
clearButton.setBackground(new java.awt.Color(200, 120, 120));
}
});
JButton loadButton = new JButton("Load Note");
loadButton.setBounds(240, 370, 110, 32);
loadButton.setBackground(new java.awt.Color(120, 180, 120));
loadButton.setForeground(java.awt.Color.WHITE);
loadButton.setFocusPainted(false);
loadButton.setFont(new java.awt.Font("Segoe UI", java.awt.Font.BOLD, 14));
loadButton.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(80, 160, 80), 2));
loadButton.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseEntered(java.awt.event.MouseEvent evt) {
loadButton.setBackground(new java.awt.Color(80, 160, 80));
}
@Override
public void mouseExited(java.awt.event.MouseEvent evt) {
loadButton.setBackground(new java.awt.Color(120, 180, 120));
}
});
// NoteManager for file operations
NoteManager noteManager = new NoteManager();
// Populate notes list
java.util.List<String> notes = noteManager.listNotes();
for (String n : notes) listModel.addElement(n);
// Save note action
saveButton.addActionListener(e -> {
String title = titleField.getText().trim();
String content = noteArea.getText();
if (title.isEmpty()) {
javax.swing.JOptionPane.showMessageDialog(frame, "Please enter a note title.");
return;
}
try {
noteManager.saveNote(title, content);
if (!listModel.contains(title)) listModel.addElement(title);
javax.swing.JOptionPane.showMessageDialog(frame, "Note saved.");
} catch (Exception ex) {
javax.swing.JOptionPane.showMessageDialog(frame, "Error saving note: " + ex.getMessage());
}
});
// Clear action
clearButton.addActionListener(e -> {
titleField.setText("");
noteArea.setText("");
});
// Load note action
loadButton.addActionListener(e -> {
String selected = notesList.getSelectedValue();
if (selected == null) {
javax.swing.JOptionPane.showMessageDialog(frame, "Select a note to load.");
return;
}
try {
String content = noteManager.loadNote(selected);
titleField.setText(selected);
noteArea.setText(content);
} catch (Exception ex) {
javax.swing.JOptionPane.showMessageDialog(frame, "Error loading note: " + ex.getMessage());
}
});
// Double-click on list to load
notesList.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
if (evt.getClickCount() == 2) {
String selected = notesList.getSelectedValue();
if (selected != null) {
try {
String content = noteManager.loadNote(selected);
titleField.setText(selected);
noteArea.setText(content);
} catch (Exception ex) {
javax.swing.JOptionPane.showMessageDialog(frame, "Error loading note: " + ex.getMessage());
}
}
}
}
});
// Add credit label at the bottom
JLabel creditLabel = new JLabel("This project was made by Ishan");
creditLabel.setFont(new java.awt.Font("Segoe UI", java.awt.Font.ITALIC, 12));
creditLabel.setForeground(new java.awt.Color(120, 120, 120));
creditLabel.setBounds(10, 440, 300, 20);
// Add components to panel
panel.add(titleLabel);
panel.add(titleField);
panel.add(notesListLabel);
panel.add(listScroll);
panel.add(contentLabel);
panel.add(areaScroll);
panel.add(saveButton);
panel.add(clearButton);
panel.add(loadButton);
panel.add(creditLabel);
frame.add(panel);
frame.setVisible(true);
}
}