Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Toolkit;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JPanel;
- import javax.swing.Timer;
- @SuppressWarnings("serial")
- public class ui extends JPanel implements ActionListener {
- public int x, y;
- public Screen() {
- x = y = 10;
- Timer timer = new Timer(5, this);
- timer.start();
- }
- public void paint(Graphics g) {
- super.paint(g);
- Graphics2D gc = (Graphics2D) g;
- gc.setPaint(Color.BLUE);
- gc.fillRect(x, y, 100, 100);
- Toolkit.getDefaultToolkit().sync();
- g.dispose();
- }
- public void actionPerformed(ActionEvent e) {
- x += 1;
- y += 1;
- if (x>800 && y>600)
- x = y = 0;
- repaint();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement