62,623
社区成员
发帖
与我相关
我的任务
分享import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class YiDong extends JFrame {
int i=0,j=0;
JPanel p=new JPanel();
ActionListener taskPerformer=new ActionListener(){
public void actionPerformed(ActionEvent ae){
if(j<400){
j=j+4;
}
else
j=0;
if(i>0){
i=i-4;
}
else
i=400;
repaint();
}
};
public YiDong(){
this.setContentPane(p);
this.setSize(400,300);
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
new Timer (100,taskPerformer).start();
}
public void paint(Graphics g){
g.clearRect(0,0,400,400);
g.drawString("举头望明月",j,60);
g.drawString("低头思故乡",i,80);
}
public static void main(String[] args){
new YiDong();
}
}