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 ...
Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.