Java Reference
In-Depth Information
Exercise P1.8. Type in and run the following program:
import javax.swing.JOptionPane;
public class DialogViewer
{
public static void main(String[] args)
{
String name =
JOptionPane.showInputDialog("What is your name?");
System.out.println(name);
System.exit(0);
}
}
Then modify the program to print ȒHello, name!ȓ, displaying the name that
the user typed in.
Additional programming exercises are available in WileyPLUS.
PROGRAMMING PROJECTS
Project 1.1. This project builds on Exercises P1.7 and P1.8. Your
program should read the user's name, then show a sequence of two dialog
boxes:
¤ First, an input dialog box that asks: ȒWhat would you like me to
do?ȓ
¤ Then a message dialog box that says: ȒI'm sorry, (your name). I'm
afraid I can't do that.ȓ
31
32
ANSWERS TO SELF-CHECK QUESTIONS
1. A program that reads the data on the CD and sends output to the speakers
and the screen.
2. A CD player can do one thingȌplay music CDs. It cannot execute programs.
3. NoȌthe program simply executes the instruction sequences that the
programmers have prepared in advance.