-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClassesScreen.java
337 lines (288 loc) · 9.64 KB
/
ClassesScreen.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
331
332
333
334
335
336
337
package ws.thurn.dossier;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import javax.swing.BoxLayout;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
/**
* The ClassesScreen class generates the GUI for one of the primary classes
* which can be accessed from the Main Menu. It handles all of the interactions
* with classes and students.
*
* @author Derek Thurn
*/
public class ClassesScreen extends Screen implements ActionListener
{
JLabel Title;
JPanel top;
JPanel opt;
JLabel info;
JButton create;
JButton cancel;
JPanel upper;
JTextField schoolNameField;
JLabel schoolNameLabel;
JTextField teacherNameField;
JLabel teacherNameLabel;
JTextField classNameField;
JLabel classNameLabel;
JPanel mid;
JPanel low;
JPanel doIt;
JPanel classInfo;
JFrame newClass = new JFrame();
Object selected;
JButton newClss;
JButton deleteClass;
JButton modifyStudents;
JButton modifyClass;
JButton selectClass;
JList cList;
DefaultListModel model;
/**
* Creates a new Classes Screen.
*/
public ClassesScreen()
{
super.init();
GUI();
initScreen();
}
/**
* Displays the GUI
*
* @pre specific GUI objects have been declared
* @post the GUI has been displayed.
*/
public void GUI()
{
frm.setTitle( "Classes" );
BoxLayout buttonLayout = new BoxLayout( content,
javax.swing.BoxLayout.Y_AXIS );
content.setLayout( buttonLayout );
newClss = new JButton( "Create New Class" );
newClss.addActionListener( this );
content.add( newClss );
deleteClass = new JButton( "Delete Selected Class" );
deleteClass.addActionListener( this );
content.add( deleteClass );
modifyClass = new JButton( "Modify Selected Class" );
modifyClass.addActionListener( this );
content.add( modifyClass );
modifyStudents = new JButton( "Modify Students" );
modifyStudents.addActionListener( this );
content.add( modifyStudents );
selectClass = new JButton( "Select This Class" );
selectClass.addActionListener( this );
content.add( selectClass );
}
/**
* Displays more GUI
*
* @pre additional specific GUI objects are declared
* @post the GUI is generated
*/
public void initScreen()
{
if( GradeBook.getNumClasses() == 0 )
{
frm.dispose();
new NewClassScreen();
return;
}
mid = new JPanel();
content.add( mid );
JPanel tempMidRep = new JPanel();
mid.add( tempMidRep );
tempMidRep.setLayout( new BorderLayout() );
mid.setLayout( null );
tempMidRep.setBounds( 0, 0, 200, 200 );
mid.setPreferredSize( new Dimension( 200, 200 ) );
// low = new JPanel();
// frm.add(low);
// low.setPreferredSize(new Dimension(1000, 1000));
// low.setSize(new Dimension(1000, 1000));
String[] entries = GradeBook.getClassesStringArray();
cList = new JList( entries );
JScrollPane scrollPane2;
scrollPane2 = new JScrollPane();
scrollPane2.setViewportView( cList );
tempMidRep.add( scrollPane2, BorderLayout.CENTER );
MyListListener listener = new MyListListener();
cList.addListSelectionListener( listener );
cList.setFixedCellHeight( 15 );
}
/**
* @author Derek Thurn Listens for changes in the JList
*/
private class MyListListener implements ListSelectionListener
{
public void valueChanged( ListSelectionEvent event )
{
if( !event.getValueIsAdjusting() )
{
Object selection = cList.getSelectedValue();
selected = selection;
}
}
}
/**
* Listens for button clicks.
*
* @pre The listeners have been added.
* @post none
*/
public void actionPerformed( ActionEvent evt )
{
if( evt.getSource().equals( back ) )
{
frm.dispose();
new MainMenu();
}
if( evt.getSource().equals( newClss ) )
{
frm.dispose();
new NewClassScreen();
}
if( evt.getSource().equals( deleteClass ) )
{
if( selected == null )
{
JOptionPane.showMessageDialog( null,
"You must select a class to delete.", "Error",
JOptionPane.ERROR_MESSAGE );
return;
}
GradeBook.deleteClass( (String) ( selected ) );
selected = null;
frm.dispose();
if( GradeBook.getNumClasses() > 0 )
new ClassesScreen();
if( GradeBook.getNumClasses() == 0 )
new NewClassScreen();
}
if( evt.getSource().equals( modifyStudents ) )
{
if( GradeBook.getCurrentClass() == null )
{
GradeBook
.error( "You must select a class to modify its students." );
return;
}
frm.dispose();
Klass temp = new Klass();
temp = GradeBook.getCurrentClass();
new ModifyStudentsScreen( temp );
}
if( evt.getSource().equals( modifyClass ) )
{
if( selected == null )
{
GradeBook
.error( "You must select a class to modify its information." );
return;
}
frm.dispose();
Klass temp = new Klass();
temp = GradeBook.getClassFromString( selected.toString() );
new ModifyClassScreen( temp );
}
if( evt.getSource().equals( selectClass ) )
{
if( selected == null )
{
GradeBook
.error( "You must select a class to mark it as selected for the program." );
return;
}
Klass temp = new Klass();
temp = GradeBook.getClassFromString( selected.toString() );
GradeBook.setCurrentClass( temp );
JOptionPane
.showMessageDialog(
null,
"The class "
+ temp
+ " has been selected. You can now modify grades and assignments for it.",
"Done", JOptionPane.INFORMATION_MESSAGE );
currentCombo.setSelectedIndex( GradeBook.getCurrentClassLocation() );
}
if( evt.getSource().equals( currentCombo ) )
{
if( currentCombo.getSelectedItem() == null )
return;
Klass temp2 = GradeBook.getCurrentClass();
String cl = currentCombo.getSelectedItem().toString();
Klass temp;
temp = GradeBook.getClassFromString( cl );
GradeBook.setCurrentClass( temp );
if( !temp.equals( temp2 ) )
{
frm.dispose();
new ClassesScreen();
}
}
if( evt.getSource().equals( save ) )
{
if( GradeBook.getCurrentClass() == null )
{
GradeBook.error( "You must select a class to save." );
return;
}
File f = GradeBook.getSaveFile();
try
{
RandomAccessFile io = new RandomAccessFile( f, "rw" );
long classAt = GradeBook.fileFindClass( GradeBook
.getCurrentClass() );
if( classAt == -1 )
{
new FileSaver( io, GradeBook.getCurrentClass() );
GradeBook.info( "The class "
+ GradeBook.getCurrentClass().toString()
+ " has been sucessfully saved." );
}
else
{
new FileSaver( io, GradeBook.getCurrentClass(), classAt );
GradeBook.info( "The class "
+ GradeBook.getCurrentClass().toString()
+ " has been sucessfully saved." );
}
}
catch( IOException e )
{
GradeBook.error( "IO Exception in CLASS SCREEN!" );
}
}
if( evt.getSource().equals( load ) )
{
if( GradeBook.getSaveFile().length() < 100 )
{
GradeBook.error( "No classed saved." );
return;
}
frm.dispose();
new FileLoadUI( "classes" );
}
if( evt.getSource().equals( knew ) )
{
frm.dispose();
new NewClassScreen();
}
}
}