... paintComponent(Graphics g) 36      {
37         super.paintComponent(g); // clears drawing area
38
39          // draw all points
40          for (Point point : points)
41             g.fillOval(point.x, point.y, 4, 4);
42      }
43   }

Fig. 26.35 Testing PaintPanel.

 1   // Fig. 26.35: Painter.java
 2   // Testing PaintPanel.
 3   import java.awt.BorderLayout;
 4   import javax.swing.JFrame;
 5   import javax.swing.JLabel;
 6
 7   public class Painter
 8   {
 9      public static void main(String[] args)
10      {
11         // create JFrame
12         JFrame application = new JFrame("A simple paint program");
13
14         PaintPanel paintPanel = new PaintPanel();
15         application.add(paintPanel, BorderLayout.CENTER);
16
17         // create a label and place it in SOUTH of BorderLayout
18         application.add(new JLabel("Drag the mouse to draw"),
19            BorderLayout.SOUTH ...

Get Java How to Program, Early Objects, 11th 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.