这个小程序,从左向右画矩形,请问如何修正,消除左边多余的部分
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.Timer;
public class A extends JFrame {
int x = 0;
A() {
Timer tm = new Timer(1000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
repaint();
x += 20;
}
});
tm.start();
}
public void paint(Graphics g) {
g.fill3DRect(x, 22, 50, 50, true);
}
public static void main(String[] args) {
A a = new A();
a.setVisible(true);
a.setSize(600, 300);
}
}
|