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);
p.add(goButton = new JButton("Try"));
goButton.addActionListener(runner);
JButton cb;
p.add(cb = new JButton("Clear Log"));
cb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
results.setText("");
}
});
JButton sb;
p.add(sb = new JButton("Save Log"));
sb.setEnabled(false);
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));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack(); // end of GUI portion
// Create a pair of Piped Streams.
is = new PipedInputStream();
os = new PipedOutputStream(is);
iis = new BufferedReader(new InputStreamReader(is, "ISO8859_1"));
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) {
JOptionPane.showMessageDialog(null,
"*** Input or Output error ***\n" + ex,
"Error",
JOptionPane.ERROR_MESSAGE);
}
}
}.start();