-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProcessorViewPanel.java
38 lines (33 loc) · 1.03 KB
/
ProcessorViewPanel.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
package pippin;
import java.util.Observer;
import java.awt.GridLayout;
import java.util.Observable;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class ProcessorViewPanel implements Observer {
private MachineView machineView;
private JTextField acc = new JTextField();
private JTextField pc = new JTextField();
public ProcessorViewPanel(MachineView machineView) {
this.machineView = machineView;
machineView.addObserver(this);
}
public JComponent createProcessorDisplay() {
JPanel returnPanel = new JPanel();
returnPanel.setLayout(new GridLayout(1,0));
returnPanel.add(new JLabel("Accumulator: ", JLabel.RIGHT));
returnPanel.add(acc);
returnPanel.add(new JLabel("Program Counter: ", JLabel.RIGHT));
returnPanel.add(pc);
return returnPanel;
}
@Override
public void update(Observable arg0, Object arg1) {
if(machineView != null) {
acc.setText("" + machineView.getAccumulator());
pc.setText("" + machineView.getProgramCounter());
}
}
}