Class TestDraw

Class TestDraw in Fig. 8.19 sets up a new window to display our drawing. Since we’re setting the coordinates for the lines only once in the constructor, the drawing does not change if paintComponent is called to refresh the drawing on the screen.

 1   // Fig. 8.19: TestDraw.java 2   // Creating a JFrame to display a DrawPanel. 3   import javax.swing.JFrame; 4  5   public class TestDraw 6   { 7      public static void main(String[] args) 8      { 9         DrawPanel panel = new DrawPanel();10         JFrame app = new JFrame();11 12         app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);13         app.add(panel);14         app.setSize(300, 300);15         app.setVisible(true);16      }17   } ...

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.