练习内容
感想
- 要赶进度,不能被练习遍数拘泥
- 抄几遍,看一遍,再默写几遍
附件
import java.awt.*;
public class MyBall{
public static void main(String[] args) {
Frame w = new Frame();
w.setSize(300,400);
MyPanel mp = new MyPanel();
Thread t = new Thread(mp);
w.add(mp);
t.start();
w.show();
}
}
class MyPanel extends Panel implements Runnable{
int x = 30;
int y = 30;
public void paint(Graphics g) {
g.fillOval(x,y,50,100);
} //要补全paint()方法的括号
public void run() {
while(true) {
y++;
if (y>400) {
y = 0;
}
try {
Thread.sleep(30);
}catch(Exception e) {} //Exception拼写
repaint();
}
}
}