Class DrawPanelTest
To display the DrawPanel on the screen, you must place it in a window. You create a window with an object of class JFrame. In DrawPanelTest.java (Fig. 4.19), line 3 imports class JFrame from package javax.swing. Line 10 in main creates a DrawPanel object, which contains our drawing, and line 13 creates a new JFrame that can hold and display our panel. Line 16 calls JFrame method setDefaultCloseOperation with the argument JFrame.EXIT_ON_CLOSE to indicate that the application should terminate when the user closes the window. Line 18 uses class JFrame’s add method to attach the DrawPanel to the JFrame. Line 19 sets the size of the JFrame. Method setSize takes two parameters that represent the width and height of the JFrame ...
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