Chapter 4, 4.10

1. Write a code segment that uses an I/O dialog box to prompt the user for her name.

- String inputStr = JOptionPane.showInputDialog(“Enter your name”, “”);.

2. Write a code segment that displays your name and address in a message box. Your name and address should be formatted on separate lines by using the “\n” character.

-JOptionPane.showMessageDialog(null, “David Chen” + “\nMA”)

3. Explain why we need to use the methods Integer.parseInt and Double.parseDouble when receiving numeric input from an I/O dialog box:

- The reason for it is that the input from an I/O box is always in the string type, and therefore, even if it is a numeric value, it can’t be applied to usage directly, but through a conversion from string value to numeric value.

4. give an example of a situation where you would want a panel to set its preferred size, rather than allow the size of the main window to determine that.

-When you want a specific size of the panel.

Leave a Comment