June 2017
Beginner
1296 pages
69h 23m
English
... 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 }
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 ...Read now
Unlock full access