Beginning Programming with Windows


The following program lets you enter in names and then print them out 
on JOptionPane which is a real window.

The key point to get here is that the output is all added to one
string and then outputted all at once.

The line
 JOptionPane.showMessageDialog( null, s ); 
prints out to the window the whole String. Adding on the
"\n" puts returns between each answer.

1. Get this program working.

import javax.swing.JOptionPane;
import java.io.*;

public class WindowTest {
public static input in = new input();

   public static void main( String[] args ) throws IOException
   {

String s = "";
String na="";
while (! na.equals("done"))
  {System.out.println("Enter a name or done");
  na = in.getString();
  if (! na.equals("done"))
    s = s + na + "\n";
  }

    JOptionPane.showMessageDialog( null, s );  // display output all at once
      System.exit( 0 );
   } 
}