All pastes #315420 Raw Edit

Untitled

public text v1 · immutable
#315420 ·published 2007-01-13 16:09 UTC
rendered paste body
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 {

	/* declare some swing components */
	private JButton addButton, statusButton;
	private JTextField ip;
	private JTable table;	
	private JScrollPane scrollPane;
	
	/* create some objects */
	private status stat = new status();
	private hosts hoot = new hosts();
	
	public frame() {
		/* initialise JFrame */
		super("NAD");
		setSize(500,400);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		/* content Pane */
		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 object */
		ButtonHandler handler = new ButtonHandler();

		addButton = new JButton ("add");
		panel1.add(addButton);
		addButton.addActionListener(handler);
		panel1.add(new JButton("ping"));
		content.add(panel1, BorderLayout.SOUTH);
		
		/* create the center JPanel */
		JPanel box = new JPanel(new FlowLayout());
		// box.setPreferredSize(new Dimension(400, 300));			
		
		
		// Create columns names
		String columnNames[] = { "Status", "IP Address", "Operating System" };

		// Create some data
	    String dataValues[][] =
		{
			{ "Alive :)", "54.24.654.23", "Linux" },
			{ "Down :(", "654.43.56.23", "Windows XP" },
			{ "Alive :)", "456.12.56.45", "Mac OS X" }, 
		};	
		

		

		table = new JTable( dataValues, columnNames );
		scrollPane = new JScrollPane( table );
		
		box.add(scrollPane);
		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 {
		private control cont = new control();
		
		public ArrayList<hosts> ar = new ArrayList<hosts>();
		
		public void actionPerformed( ActionEvent actionEvent )
		{
			if (actionEvent.getSource() == addButton) 
			{
				cont.addServer(ip.getText());
				hosts b=new hosts();
				ar.add(b); 
				b.setHost(ip.getText());
				b.setOS(cont.response);
				System.out.println("ArrayList Size: " + ar.size());
		
			}
			else if (actionEvent.getSource() == statusButton)
			{
				/* Get the Status */
			}
		}
	} // end events
		
} /* end frame class */