JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.Timer
public class RectangkeFrame extends JFrame
{
private static final int FRAME_WIDTH = 300;
private static final int FRAME_HEIGHT = 400;
private RectangleComponent scene;
class TimerListener implements ActionListener
{ public void actionPerformed (ActionEvent event)
{
scene.moveRectangleBy(1,1);
}
}
public RectangleFrame(){
RectangleFrame b=new RectangleFrame();
scene=new RectangleComponent();
scene.add(b);
setSize(FRAME_WIDTH, FRAME_HEIGHT);
ActionListener listener=new TimerListener();
final int DELAY=100;
Timer t=new Timer(DELAY,listener);
t.start();
}
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run