Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
73
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.awt.Color;
  2. import java.awt.Graphics;
  3. import java.awt.Graphics2D;
  4. import java.awt.Toolkit;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7.  
  8. import javax.swing.JPanel;
  9. import javax.swing.Timer;
  10.  
  11. @SuppressWarnings("serial")
  12. public class ui extends JPanel implements ActionListener {
  13.     public int x, y;
  14.     public Screen() {
  15.         x = y = 10;
  16.         Timer timer = new Timer(5, this);
  17.         timer.start();
  18.     }
  19.  
  20.     public void paint(Graphics g) {
  21.         super.paint(g);
  22.         Graphics2D gc = (Graphics2D) g;
  23.  
  24.         gc.setPaint(Color.BLUE);
  25.         gc.fillRect(x, y, 100, 100);
  26.         Toolkit.getDefaultToolkit().sync();
  27.         g.dispose();
  28.     }
  29.  
  30.     public void actionPerformed(ActionEvent e) {
  31.         x += 1;
  32.         y += 1;
  33.         if (x>800 && y>600)
  34.             x = y = 0;
  35.         repaint();
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement