-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileLoadUI.java
154 lines (137 loc) · 4.43 KB
/
FileLoadUI.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
package ws.thurn.dossier;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
/**
* The FileLoadUI class generates the GUI for letting the user select a class to
* load from the save file into the program.
*
* @author Derek Thurn
*/
public class FileLoadUI implements ActionListener
{
private JFrame cFrame;
private JPanel one;
JButton cancel;
JButton load;
private JPanel two;
private JList cList;
private String selectedClass;
// Which class the user has selected.
String screen;
// The previous screen which the user was on.
/**
* Creates a new File Load screen, storing which screen the user came from.
*
* @param scr
*/
public FileLoadUI( String scr )
{
display();
screen = scr;
}
/**
* Displays the GUI
*
* @pre the required GUI objects have been declared
* @post the GUI has been displayed
*/
public void display()
{
cFrame = new JFrame();
cFrame.setTitle( "Load Class" );
cFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
{
{
two = new JPanel();
cFrame.getContentPane().add( two, BorderLayout.NORTH );
two.setPreferredSize( new java.awt.Dimension( 392, 340 ) );
}
one = new JPanel();
cFrame.getContentPane().add( one, BorderLayout.CENTER );
one.setPreferredSize( new java.awt.Dimension( 392, 32 ) );
one.setSize( 392, 32 );
{
load = new JButton( "Load Class" );
load.addActionListener( this );
one.add( load );
}
{
cancel = new JButton( "Cancel" );
cancel.addActionListener( this );
one.add( cancel );
}
{
cList = new JList( GradeBook.getSavedClasses() );
JScrollPane scrollPane2;
scrollPane2 = new JScrollPane( cList );
scrollPane2.setPreferredSize( new Dimension( 200, 200 ) );
two.add( scrollPane2 );
ListListener listener = new ListListener();
cList.addListSelectionListener( listener );
}
}
cFrame.setSize( 400, 400 );
GradeBook.center( cFrame );
cFrame.setVisible( true );
}
/**
* Listens for button clicks.
*
* @pre The correct listeners have been added.
* @post none
*/
public void actionPerformed( ActionEvent evt )
{
if( evt.getSource().equals( cancel ) )
{
cFrame.dispose();
if( screen.equals( "classes" ) )
new ClassesScreen();
if( screen.equals( "assignments" ) )
new AssignmentsScreen();
if( screen.equals( "grades" ) )
new GradesScreen();
if( screen.equals( "reports" ) )
new ReportsScreen();
if( screen.equals( "help" ) )
new HelpScreen();
}
if( evt.getSource().equals( load ) )
{
if( selectedClass == null || selectedClass.equals( "" ) )
{
GradeBook.error( "You must select a class to load." );
return;
}
Klass temp = new Klass( selectedClass );
new FileLoader( GradeBook.getSaveFile(), temp );
GradeBook.info( "Class loaded successfully." );
}
}
/**
* @author Derek Thurn Listens for changes in the JList
*/
private class ListListener implements ListSelectionListener
{
public void valueChanged( ListSelectionEvent event )
{
if( !event.getValueIsAdjusting() )
{
if( event.getSource().equals( cList ) )
{
Object selection = cList.getSelectedValue();
selectedClass = selection.toString();
}
}
}
}
}