河南成教 / Java程序设计
[简答题] 阅读下列程序,请写出该程序的功能。
import java.applet.*; import java.awt.*;
public class Class1 extends java.applet.Applet implements Runnable {
Thread myThread = null;
public void start() {
setSize(500, 400);
if (myThread == null) {
myThread = new Thread(this); myThread.start();
}
}
public void run() {
while (myThread != null) {
try { myThread.sleep(500);
} catch (InterruptedException e) { }
repaint();
}
}
public void paint(Graphics g) {
int x = (int)(400*Math.random());
int y = (int)(300*Math.random());
g.setColor(Color.red); g.fillOval(x,y, 10, 10);
}
}
import java.applet.*; import java.awt.*;
public class Class1 extends java.applet.Applet implements Runnable {
Thread myThread = null;
public void start() {
setSize(500, 400);
if (myThread == null) {
myThread = new Thread(this); myThread.start();
}
}
public void run() {
while (myThread != null) {
try { myThread.sleep(500);
} catch (InterruptedException e) { }
repaint();
}
}
public void paint(Graphics g) {
int x = (int)(400*Math.random());
int y = (int)(300*Math.random());
g.setColor(Color.red); g.fillOval(x,y, 10, 10);
}
}
参考答案:
佳题速递: