-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainFrame.java
245 lines (221 loc) · 11.3 KB
/
MainFrame.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
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package GUI;
/**
* Justin Schoen
* September 10, 2014
* This program reads process information from a text area,
* creates an appropriate data structure, and outputs the contents of the
* data structure to a second text area. The program adds a process to the newList
* when the clock reaches the creation time. When the clock goes one tick past the
* creation time, the process in the newList is added to the ready list.
* For full description, see http://raider.mountunion.edu/csc/CSC370/Fall2014/projects/project2.html
* This project is basically an operating system moving processes from the new to ready to running to waiting until it gets
* terminated.
*
*
*/
/**
* Work Log:
* 8/28: Created GUI with buttons and text fields-1 hour
* 9/1: Worked on runnable clock-1.5 hours
* 9/2: Finished clock with pause and one tick functions-.5 hours
* 9/2: Created Process class and started data structure for processes-.5 hours
* 9/3: Added functionality to the read data and show system status buttons-2 hours
* 9/9: Developed showStatus method to add new and remove new after a second tick then add the process to the readyList-2 hours
* 9/10: Documentation and validity checks-1.5 hours
* 9/17: Data is reset when "read data" button is clicked. No processing done in showStatus method-1 hour
* 9/24: Moved process from ready state to running. Split trace tape. Set time quantum-2 hours
* 9/29: Got trace tape working accordingly and created methods in the process class to handle the tape- 3 hours
* 9/30: Sent processes back and forth from waitinglist to ready, running to ready, running to terminated- 4 hours
* 10/1: Arranged method calls in the right order to places processes in the right states- 2 hours
* 10/2: Finished setting the new tape so the processes would remember the tape- 1 hour
*/
public class MainFrame extends javax.swing.JFrame {
Structure test;
ClockStarter clock;
/**
* Creates new form MainFrame
*/
public MainFrame() {
initComponents();
test = new Structure(clockField);
clock = test.getClock();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane2 = new javax.swing.JScrollPane();
output = new javax.swing.JTextArea();
readData = new javax.swing.JButton();
oneTick = new javax.swing.JButton();
run = new javax.swing.JButton();
clockField = new javax.swing.JTextField();
showStatus = new javax.swing.JButton();
jScrollPane3 = new javax.swing.JScrollPane();
input = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
output.setColumns(20);
output.setRows(5);
jScrollPane2.setViewportView(output);
readData.setText("read data");
readData.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
readDataActionPerformed(evt);
}
});
oneTick.setText("one tick");
oneTick.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
oneTickActionPerformed(evt);
}
});
run.setText("run");
run.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
runActionPerformed(evt);
}
});
clockField.setFont(new java.awt.Font("Tahoma", 0, 48)); // NOI18N
clockField.setText("0");
clockField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
clockFieldActionPerformed(evt);
}
});
showStatus.setText("show status");
showStatus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
showStatusActionPerformed(evt);
}
});
input.setColumns(20);
input.setRows(5);
input.setText("4\n2\nA\nC 5 I 9 C 6 I 7 C 2");
jScrollPane3.setViewportView(input);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2)
.addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 448, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(oneTick, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(readData, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(showStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(run, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(clockField, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(oneTick)
.addGap(18, 18, 18)
.addComponent(run))
.addComponent(clockField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(readData)
.addGap(32, 32, 32)
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(27, 27, 27)
.addComponent(showStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void readDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_readDataActionPerformed
// TODO add your handling code here:
test.readData(input, output, clockField);
}//GEN-LAST:event_readDataActionPerformed
private void oneTickActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oneTickActionPerformed
// TODO add your handling code here:
clock.incrementTime();
test.processStuff();
test.showStatus(output, clockField, input);
}//GEN-LAST:event_oneTickActionPerformed
private void runActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_runActionPerformed
// TODO add your handling code here:
if(run.getText().equals("run")){
run.setText("pause");
clock.setRunning(true);
System.out.println("running");
}
else{
clock.setRunning(false);
run.setText("run");
System.out.println("paused");
}
}//GEN-LAST:event_runActionPerformed
private void showStatusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showStatusActionPerformed
// TODO add your handling code here:
System.out.println("show status");
test.showStatus(output, clockField, input);
}//GEN-LAST:event_showStatusActionPerformed
private void clockFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clockFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_clockFieldActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextField clockField;
private javax.swing.JTextArea input;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JButton oneTick;
private javax.swing.JTextArea output;
private javax.swing.JButton readData;
private javax.swing.JButton run;
private javax.swing.JButton showStatus;
// End of variables declaration//GEN-END:variables
}