Newer
Older
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
package fucoin.gui;
import fucoin.supervisor.SuperVisorImpl;
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class SuperVisorGuiControlImpl implements SuperVisorGuiControl {
private SuperVisorImpl superVisor;
private JFrame frame;
public SuperVisorGuiControlImpl(SuperVisorImpl sv) {
superVisor = sv;
init();
}
private void init() {
//Show AWT window for runtime information
frame = new JFrame("Server");
frame.setLayout(new GridLayout(3, 2));
frame.add(new Label("All Amounts:"));
//Init Amount Table and SuperVisorImpl
JTable amountListView = new JTable(superVisor.getAmountTableModel());
Label averageAmountLbl = new Label("Average Amounts:");
frame.add(new JScrollPane(amountListView));
frame.add(new Label("Average Amounts:"));
frame.add(averageAmountLbl);
//Call update on supervisor
JButton updateBtn = new JButton("Update");
updateBtn.addActionListener(e -> superVisor.updateValues());
frame.add(updateBtn);
//Exit Button and shutdown supervisor
JButton exitBtn = new JButton("exit");
exitBtn.addActionListener(e -> {
superVisor.exit();
frame.setVisible(false);
frame.dispose();
});
frame.add(exitBtn);
frame.setSize(200, 400);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
superVisor.exit();
}
});
}
@Override
public void onLeave() {
frame.dispose();
}
@Override
public void log(String message) {
// One day, we may have a server log GUI as well..
// Until then, we just print it to the console
System.out.println(message);
}