FileDocCategorySizeDatePackage
TestOpenMailRelayGUI.javaAPI DocExample2698Sat Mar 31 17:18:14 BST 2001None

TestOpenMailRelayGUI

public class TestOpenMailRelayGUI extends JFrame
GUI for TestOpenMailRelay, lets you run it multiple times in one JVM to avoid startup delay. Starts each in its own Thread for faster return to ready state. Uses PipedI/OStreams to capture system.out/err into a window.

Fields Summary
JTextField
hostTextField
The one-line textfield for the user to type Host name/IP
JTextArea
results
Multi-line text area for results.
PrintStream
ps
The piped stream for the main class to write into "results"
DataInputStream
iis
The piped stream to read from "ps" into "results"
ActionListener
runner
This inner class is the action handler both for pressing the "Try" button and also for pressing in the text field. It gets the IP name/address from the text field and passes it to process() in the main class.
Constructors Summary
public TestOpenMailRelayGUI()
Construct a GUI and some I/O plumbing to get the output of "TestOpenMailRelay" into the "results" textfield.


	                 	 
	    
		super("Tests for Open Mail Relays");
		PipedInputStream is;
		PipedOutputStream os;
		JPanel p;
		Container cp = getContentPane();
		cp.add(BorderLayout.NORTH, p = new JPanel());

		// The entry label and text field.
		p.add(new JLabel("Host:"));
		p.add(hostTextField = new JTextField(10));
		hostTextField.addActionListener(runner);

		JButton b;
		p.add(b = new JButton("Try"));
		b.addActionListener(runner);

		results = new JTextArea(20, 60);
		// Add the text area to the main part of the window (CENTER).
		// Wrap it in a JScrollPane to make it scroll automatically.
		cp.add(BorderLayout.CENTER, new JScrollPane(results));

		pack();			// end of GUI portion

		// Create a pair of Piped Streams.
		is = new PipedInputStream();
		os = new PipedOutputStream(is);

		iis = new DataInputStream(is);
		ps = new PrintStream(os);

		// Construct and start a Thread to copy data from "is" to "os".
		new Thread() {
			public void run() {
				try {
					String line;
					while ((line = iis.readLine()) != null) {
						results.append(line);
						results.append("\n");
					}
				} catch(IOException ex) {
						results.append("\n");
						results.append("*** Input or Output error ***\n");
						results.append(ex.toString());
						return;
				}
			}
		}.start();
	
Methods Summary