Using the Custom JPanel in an Application
Class Painter (Fig. 12.35) contains the main method that executes this application. Line 14 creates a PaintPanel object on which the user can drag the mouse to draw. Line 15 attaches the PaintPanel to the JFrame.
Click here to view code image
1 // Fig. 12.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 JFrame12 JFrame application = new JFrame("A simple paint program");13
14 PaintPanel paintPanel = new PaintPanel();15 application.add(paintPanel, BorderLayout.CENTER);16
17 ...