Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3.  
  4. public class Mauskugel extends Frame {
  5.  
  6.     MousePositionTracker mt = new MousePositionTracker();
  7.     int x=50,y=50;
  8.  
  9.  
  10.     public Mauskugel() {
  11.         this.setSize(500,500);
  12.         this.setVisible(true);
  13.         addMouseMotionListener(mt);
  14.  
  15.         this.addWindowListener(new WindowAdapter() {
  16.             public void windowClosing(WindowEvent e)
  17.             {System.exit(0);}
  18.         });
  19.  
  20.         while (true) {
  21.             if ((mt.getX()>50)&&(mt.getX()<150)&&(mt.getY()>50)&&(mt.getY()<150)) {
  22.                 run();
  23.             }
  24.         }
  25.     }
  26.  
  27.     public void run() {
  28.         while (true) {
  29.             x=mt.getX()-12;
  30.             y=mt.getY()-12;
  31.             repaint();
  32.  
  33.             try {
  34.                 Thread.sleep(0,1);
  35.             } catch (Exception e) {};
  36.         }
  37.  
  38.     }
  39.  
  40.     public void paint (Graphics g) {
  41.         g.setColor(Color.blue);
  42.         g.fillOval(x,y,100,100);
  43.     }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement