Import java.awt. *; import java.awt.event. *; import java.util. *; import java.applet. *; //
Public Class Huatu Extends Applet Implements ActionListener, MouseMotionListener, MouseListener // Implement the button to listen, and the mouse motion listener interface, to rewrite the method in the interface {Button Button = New Button; mypanel panel = new mypanel (); ArrayList List = New ArrayList (); // Plus a list to store the point public void init (); setLayout (New borderLayout ()); add (button, "north"); Button.addActionListener (this); // Add button listener Panel.addmouseMotionListener (this); // Add a mouse motion listener Panel.addmouselistener (this); // Mouse click to listen add (panel);} public void actionperformed ActionEvent E) {list.clear (); list.add ()); panel.repaint ();} public void mousedragged (mouseevent e) {Point Point = E.GETPOINT (); // Get drag Point arraylist line = (arraylist) list.get (list.size () - 1); line.add (point); // Put your point to list () // panel.Repaint (); // Heavy painting Panel
Graphics g = panel.getgraphgraphics (); // Get the PANEL's Graphics, draw G.SetColor (color.blue); if (line.size ()> 1) // If the list is more than 1 point, draw a draw Line {Point P1 = (POINT) line.get (line.size () - 2); // LIST in the second point POINT P2 = (Point) line.get (line.size () - 1); The last point in // list g.drawline (p1.x, p1.y, p2.x, p2.y);} else {POINT P2 = (Point) line.get (line.size () - 1) G. Drawline (P2.x, P2.Y, P2.x, P2.Y); only 1 point in // List, draw a point}} public void mousemoved (mouseevent e) {} public void mouseclicked (MouseEvent e) {} public void mouseEntered (MouseEvent e) {} public void mouseExited (MouseEvent e) {} public void mousePressed (MouseEvent e) {} public void mouseReleased (MouseEvent e) // method call is released mouse { List.add (new arraylist ());} Class myPanel Extends Panel {public void Paint (graphics g) {g.setcolor (color.blue); for (int K = 0; k