-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSchedule.java
More file actions
238 lines (215 loc) · 5.87 KB
/
Schedule.java
File metadata and controls
238 lines (215 loc) · 5.87 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
package timelinr;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Schedule extends JPanel implements ActionListener{
private Base base;
private HowMany hm;
private Tasks t;
private JButton cont;
private ArrayList<ArrayList<String>> info;
public Schedule(Base b){
setLayout(new BorderLayout());
base = b;
t = new Tasks(this);
hm = new HowMany(t);
cont = new JButton("Continue");
cont.addActionListener(this);
info = new ArrayList<ArrayList<String>>();
add(hm, BorderLayout.NORTH);
add(cont, BorderLayout.SOUTH);
add(t, BorderLayout.CENTER);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == cont){
info = t.returnArray();
base.time.setST(info);
base.showIt("time");
}
}
}
class HowMany extends JPanel implements ActionListener{
private Tasks tasks;
private JTextField howMany;
private JButton contin;
private int numTasks;
public HowMany(Tasks t){
setLayout(new FlowLayout());
tasks = t;
howMany = new JTextField(10);
contin = new JButton("Continue");
numTasks = 0;
contin.addActionListener(this);
add(howMany);
add(contin);
}
public int getNumTasks(){
return numTasks;
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == contin){
try{
numTasks = Integer.parseInt(howMany.getText().trim());
tasks.setTasks(numTasks);
}catch(Exception ex){
new Error("Something went wrong, try entering a proper integer with no extra characters");
}
}
}
}
class TheTask extends JPanel implements ActionListener{
private JLabel enterName;
private JLabel enterTime;
private JLabel enterDash;
private JLabel enterColon;
public JTextField name;
public JTextField fromHour;
public JTextField fromMin;
public JTextField toHour;
public JTextField toMin;
private JMenuBar fromMBar;
private JMenuBar toMBar;
public JMenu toMenu;
public JMenu fromMenu;
private JMenuItem toAM;
private JMenuItem toPM;
private JMenuItem fromAM;
private JMenuItem fromPM;
private int curr;
public TheTask(int i){
setLayout(new FlowLayout());
curr = i;
enterName = new JLabel("Task " + curr + " name:");
enterTime = new JLabel("Time: ");
enterDash = new JLabel("-");
enterColon = new JLabel(":");
name = new JTextField(25);
fromHour = new JTextField(2);
fromMin = new JTextField(2);
toHour = new JTextField(2);
toMin = new JTextField(2);
fromMBar = new JMenuBar();
fromMenu = new JMenu("AM");
fromAM = new JMenuItem("AM");
fromPM = new JMenuItem("PM");
toMBar = new JMenuBar();
toMenu = new JMenu("AM");
toAM = new JMenuItem("AM");
toPM = new JMenuItem("PM");
add(enterName);
add(name);
add(enterTime);
add(fromHour);
add(enterColon);
add(fromMin);
fromMenu.add(fromAM);
fromMenu.add(fromPM);
fromMBar.add(fromMenu);
add(fromMBar);
add(enterDash);
add(toHour);
enterColon = new JLabel(":");
add(enterColon);
add(toMin);
toMenu.add(toAM);
toMenu.add(toPM);
toMBar.add(toMenu);
add(toMBar);
fromAM.addActionListener(this);
fromPM.addActionListener(this);
toAM.addActionListener(this);
toPM.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
Object o = e.getSource();
if(o == fromAM || o == fromPM){
fromMenu.setText(((JMenuItem)o).getText());
}
else if(o == toAM || o == toPM){
toMenu.setText(((JMenuItem)o).getText());
}
}
}
class Tasks extends JPanel{
private int tasks;
private JPanel pan;
private ArrayList<TheTask> ts;
public Tasks(JPanel p){
tasks = 0;
pan = p;
}
public void setTasks(int t){
removeAll();
tasks = t;
setLayout(new GridLayout(tasks, 1));
ts = new ArrayList<TheTask>();
for(int i = 0; i < tasks; i++){
TheTask ayy = new TheTask(i+1);
ts.add(ayy);
add(ayy);
}
revalidate();
repaint();
pan.revalidate();
pan.repaint();
}
public ArrayList<ArrayList<String>> returnArray(){
ArrayList<ArrayList<String>> arr = new ArrayList<ArrayList<String>>();
for(int i = 0; i < ts.size(); i++){
ArrayList<String> as = new ArrayList<String>();
String toHour = "";
String toMin = ts.get(i).toMin.getText().trim();
if(Integer.parseInt(ts.get(i).toHour.getText().trim()) < 10)
toHour = "0" + Integer.parseInt(ts.get(i).toHour.getText().trim());
else
toHour = "" + Integer.parseInt(ts.get(i).toHour.getText().trim());
if(ts.get(i).toMenu.getText().equals("PM") && Integer.parseInt(toHour) != 12)
toHour = "" + (Integer.parseInt(toHour)+12);
if(Integer.parseInt(toHour) == 12 && ts.get(i).toMenu.getText().equals("AM"))
toHour = "00";
String fromHour = "";
String fromMin = ts.get(i).fromMin.getText().trim();
if(Integer.parseInt(ts.get(i).fromHour.getText().trim()) < 10)
fromHour = "0" + Integer.parseInt(ts.get(i).fromHour.getText().trim());
else
fromHour = "" + Integer.parseInt(ts.get(i).fromHour.getText().trim());
if(ts.get(i).fromMenu.getText().equals("PM") && Integer.parseInt(fromHour) != 12)
fromHour = "" + (Integer.parseInt(fromHour)+12);
if(Integer.parseInt(fromHour) == 12 && ts.get(i).fromMenu.getText().equals("AM"))
fromHour = "00";
as.add(ts.get(i).name.getText());
as.add(fromHour+fromMin);
as.add(toHour+toMin);
System.out.println(as);
arr.add(as);
}
return arr;
}
}
class Error extends JFrame{
private JLabel la;
public Error(String s){
super("Error");
setSize(500, 150);
la = new JLabel(s);
setContentPane(la);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setResizable(false);
setVisible(true);
}
}