next up previous
Next: Exercises Up: Unit 02 Previous: Example: initials of a

Output to a window

Using the class JOptionPane, it is also possible to send output to a dialog window. Specifically, the method showMessageDialog() can be used. The following program illustrates its use:

import javax.swing.JOptionPane;

public class OutputWindow {
  public static void main(String[] args) {
    String name = JOptionPane.showInputDialog("What is your name?");
    name = name.toUpperCase();
    String stringToShow = "Hy " + name + ", how are you?";
    JOptionPane.showMessageDialog(null, stringToShow);
    System.exit(0);
  }
}


next up previous
Next: Exercises Up: Unit 02 Previous: Example: initials of a