Advertisement
yenqwerty

Untitled

Mar 24th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. import java.applet.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. public class Paint extends Applet {
  5.     private static final long serialVersionUID = 1L;
  6.     int last_x, last_y;
  7.     public  void  init() {
  8.  
  9.         this.addMouseListener(new MouseAdapter() {
  10.             public void mousePressed(MouseEvent e) {
  11.                 last_x = e.getX(); last_y = e.getY();
  12.             }
  13.         });
  14.  
  15.         this.addMouseMotionListener(new MouseMotionAdapter() {
  16.             public void mouseDragged(MouseEvent e) {
  17.                 Graphics g = getGraphics();
  18.                 int x = e.getX(), y= e.getY();
  19.                 g.setColor(Color.magenta);
  20.                 g.drawLine(last_x, last_y, x, y);
  21.                 last_x = x; last_y = y;
  22.             }
  23.         });
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement