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.
Click here to view code image
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 } ...