/* Distributed Systems: Practical Exercise 2 This class is the main graphical user interface class. Start the application by running this class. You should not change anything in this file. This template file (C) The University of Edinburgh, 2002 Author: Yussuf Abu Shaaban */ import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Controller extends Frame{ JButton ringButton = new JButton("Ring-Based Election Algorithm"); JButton bullyButton = new JButton("Bully Election Algorithm"); Simulator simulator = new Simulator(); public Controller(String title){ super(title); ringButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ simulator.startRingElection(); } }); bullyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ simulator.startBullyElection(); } }); Panel mainPanel = new Panel(); mainPanel.setLayout(new BorderLayout()); Panel buttonsPanel = new Panel(); buttonsPanel.setBackground(Color.gray); buttonsPanel.add(ringButton); buttonsPanel.add(bullyButton); mainPanel.add(buttonsPanel, BorderLayout.NORTH); simulator.setSize(700, 600); mainPanel.add(simulator, BorderLayout.CENTER); this.add(mainPanel); } public static void main(String[] args){ Controller controller = new Controller( "Distributed Systems Algorithms Simulator"); controller.setLocation(100, 70); controller.pack(); controller.setVisible(true); } }