/* * This class is to display the server GUI. This class will also include * immediate GUI events. */ import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; public class frame extends JFrame { JButton addButton, statusButton; JTextField ip; status stat = new status(); public frame() { /* initialise JFrame */ super("NAD"); setSize(500,400); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content=getContentPane(); content.setLayout(new BorderLayout()); /* JPanel1 */ JPanel panel1 = new JPanel(new FlowLayout()); panel1.add(new JLabel("Enter a Machine IP: ")); ip = new JTextField(10); panel1.add(ip); ButtonHandler handler = new ButtonHandler(); addButton = new JButton ("add"); panel1.add(addButton); addButton.addActionListener(handler); panel1.add(new JButton("ping")); /* add panel1 to Content pane */ content.add(panel1, BorderLayout.SOUTH); /* create the center JPanel */ JPanel box = new JPanel(new FlowLayout()); // box.setPreferredSize(new Dimension(400, 300)); hosts ho = new hosts(); box.add(new JLabel("Ip OS Version Username Java Version")); String arr[] = (String[]) ho.hostnames.toArray(new String[0]); JList li = new JList(arr); box.add(li); content.add(box, BorderLayout.CENTER); /* JPanel2 */ JPanel panel2 = new JPanel(new FlowLayout()); panel2.add(new JButton("ping")); panel2.add(new JButton("isolate")); panel2.add(new JButton("removes")); statusButton = new JButton("status"); panel2.add(statusButton); statusButton.addActionListener(handler); /* add Panel2 to ContentPane */ content.add(panel2, BorderLayout.NORTH); } /* end constructor */ /* events handler */ public class ButtonHandler implements ActionListener { public void actionPerformed( ActionEvent actionEvent ) { if (actionEvent.getSource() == addButton) { hosts hoo = new hosts(); hoo.addHost(ip.getText()); // control cont = new control(); // cont.addServer(ip.getText()); } else if (actionEvent.getSource() == statusButton) { status stat = new status(); stat.requestStatus(ip.getText()); // st.setText(stat.theOsName); } } } // end events } /* end frame class */