Class ShapesTest
Figure 5.28 is responsible for handling input from the user and creating a window to display the appropriate drawing based on the user’s response. Line 3 imports JFrame to handle the display, and line 4 imports JOptionPane to handle the input. Lines 11–13 prompt the user with an input dialog and store the user’s response in variable input. Notice that when displaying multiple lines of prompt text in a JOptionPane, you must use \n to begin a new line of text, rather than %n. Line 15 uses Integer method parseInt to convert the String entered by the user to an int and stores the result in variable choice. Line 18 creates a Shapes object and passes the user’s choice to the constructor. Lines 20–25 perform the standard operations ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access