The following looks:
 
 | 01 | importjava.awt.*; | 
| 02 | importjava.awt.event.*; | 
| 03 | importjavax.swing.*; | 
| 04 | 
| 05 | publicclassPainter extendsJFrame { | 
| 06 |     privateintpointCount = 0; | 
| 07 |     privatePoint points[] = newPoint[1000]; | 
| 08 | 
| 09 |     publicPainter () { | 
| 10 |         super("Program menggambar sederhana"); | 
| 11 | 
| 12 |         getContentPane().add(newJLabel("Drag mouse to draw"), BorderLayout.SOUTH); | 
| 13 | 
| 14 |         addMouseMotionListener ( | 
| 15 |             newMouseMotionAdapter() { | 
| 16 |                 publicvoidmouseDragged (MouseEvent e) { | 
| 17 |                     if(pointCount < points.length) { | 
| 18 |                         points[pointCount] = e.getPoint(); | 
| 19 |                         ++pointCount; | 
| 20 |                         repaint(); | 
| 21 |                     } | 
| 22 |                 } | 
| 23 |             } //end of anonymous class | 
| 24 |         ); //end method addMotionListener | 
| 25 | 
| 26 |         setSize (300,150); | 
| 27 |         setLocationRelativeTo(null); | 
| 28 |         setVisible(true); | 
| 29 |     } | 
| 30 | 
| 31 |     publicvoidpaint (Graphics g) { | 
| 32 |         super.paint(g); | 
| 33 |         for(inti = 0; i < points.length && points[i] != null; i++) { | 
| 34 |             g.setColor(Color.red); | 
| 35 |             g.fillOval (points[i].x, points[i].y, 4,4); | 
| 36 |         } | 
| 37 |     } | 
| 38 | 
| 39 |     publicstaticvoidmain (String args[]) { | 
| 40 |         Painter test = newPainter(); | 
| 41 |         test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | 
| 42 |     } | 
| 43 | } | 

 
 
  
0 komentar: