COMP2396
Loading...
Searching...
No Matches
SimpleAnimation.java
Go to the documentation of this file.
1import javax.swing.*;
2import java.awt.*;
3
4public class SimpleAnimation {
5 int x = 70;
6 int y = 70;
7
8 public static void main(String[] args) {
10 gui.go();
11 }
12
13 public void go() {
14 JFrame frame = new JFrame();
15 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
16 MyAnimPanel animPanel = new MyAnimPanel();
17 frame.add(animPanel);
18 frame.setSize(300, 300);
19 frame.setVisible(true);
20 for (int i = 0; i < 130; i++) {
21 x++;
22 y++;
23 animPanel.repaint();
24 try {
25 Thread.sleep(50);
26 } catch (Exception ex) { }
27 }
28 } // close go() method
29
30 class MyAnimPanel extends JPanel {
31 public void paintComponent(Graphics g) {
32 g.clearRect(0, 0, this.getWidth(), this.getHeight());
33 g.setColor(Color.GREEN);
34 g.fillOval(x, y, 40, 40);
35 }
36 } // close inner class
37
38} // close outer class
static void main(String[] args)