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); } }