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 ...

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.