-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreminder.java
More file actions
123 lines (96 loc) · 4.56 KB
/
reminder.java
File metadata and controls
123 lines (96 loc) · 4.56 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
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class reminder{
public static void main(String[] args) {
JFrame window = new JFrame("Scheduler");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setSize(900,700);
window.setLayout(new BorderLayout());
JPanel daysPanel = new JPanel(new GridLayout(1, 7, 10, 10));
String[] days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
HashMap<String, List<String>> scheduleData = new HashMap<>();
for (String d : days) scheduleData.put(d, new ArrayList<>());
for (String day : days) {
JButton dayBox = new JButton(day);
dayBox.setFont(new Font("Arial", Font.BOLD, 12));
JPanel dayButtonsAlign = new JPanel(new FlowLayout(FlowLayout.CENTER));
dayBox.setPreferredSize(new Dimension(150,550));
dayBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String time = JOptionPane.showInputDialog(window, "Enter time for " + day + ":");
String title = JOptionPane.showInputDialog(window, "Enter title for " + day + ":");
if (time != null && title != null) {
String entry = time + " - " + title;
scheduleData.get(day).add(entry);
StringBuilder display = new StringBuilder("<html><center>" + day + "<br/>");
for (String r : scheduleData.get(day)) {
display.append(r).append("<br/>");
}
display.append("</center></html>");
dayBox.setText(display.toString());
}
}
});
dayButtonsAlign.add(dayBox);
daysPanel.add(dayBox);
}
JButton exportBtn = new JButton("Export Schedule");
exportBtn.setFont(new Font("Arial", Font.BOLD, 16));
exportBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int choice = chooser.showSaveDialog(window);
if (choice == JFileChooser.APPROVE_OPTION) {
File dir = chooser.getSelectedFile();
File report = new File(dir, "Reminder.txt");
try (BufferedWriter writer = new BufferedWriter(new FileWriter(report))) {
for (String d : days) {
writer.newLine();
writer.write("=== " + d + " ===");
writer.newLine();
List<String> reminders = scheduleData.get(d);
if (reminders.isEmpty()) {
writer.write(" ");
} else {
for (String r : reminders) {
writer.write(" task: " + r);
writer.newLine();
}
}
writer.newLine();
}
JOptionPane.showMessageDialog(window, "Report saved at: " + report.getAbsolutePath());
} catch (IOException ex) {
JOptionPane.showMessageDialog(window, "Error saving file: " + ex.getMessage());
}
}
}
});
JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
exportBtn.setPreferredSize(new Dimension(300, 80));
bottomPanel.add(exportBtn);
window.add(daysPanel, BorderLayout.CENTER);
window.add(bottomPanel, BorderLayout.SOUTH);
window.setVisible(true);
}
}