如何用JAVA画随机圆

来源:百度知道 编辑:UC知道 时间:2024/09/28 08:42:12
RT 自动出现大小不一样的圆 位置与颜色随机 要用Appelt实现

import java.applet.Applet;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.util.Random;

public class Number8 extends Applet{
int x,y; //圆的位置
int W_H; //圆的大小
int R,G,B; //圆的颜色
Random rd = new Random();

public void init(){
this.resize(400, 300);
}
public void paint(Graphics g){

while ( true ){
W_H = rd.nextInt(100);

x = rd.nextInt(this.getWidth());
y = rd.nextInt(this.getHeight());

R = rd.nextInt(255);
G = rd.nextInt(255);
B = rd.nextInt(255);

g.setColor(Color.white);
g.fillRect(0,0,this.getWidth(),this.getHeight());

Color color = new Color(R,G,B);
g.setColor(color);
g.fillArc(x,y,W_H,W_H,0,360);

try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}<