📄 lab7b.java
字号:
import java.awt.*;
import java.applet.Applet;
public class lab7b extends Applet {
public void paint(Graphics g){
int i=1;
while(i==1)
paintt(g);
}
public void paintt(Graphics page) {
Color c1,c2,c3;
int width= (int)(Math.random()* 41);
int boxNum= 8;
int xValue= (int)(Math.random()* 41);
int yValue= (int)(Math.random()* 41);
c1=mixColor();
c2=mixColor();
c3=mixColor();
page.setColor(c3);
page.fillRect (0, 0, getSize().width, getSize().height);
page.setColor(c1);
int diameter=width;
int y=xValue;
for (int i = 0; i< boxNum; i ++){
int x=yValue;
for ( int j =0; j <boxNum; j++){
if( page.getColor() == c1)
page.setColor(c2);
else
page.setColor(c1);
page.fillRect (x,y,diameter, diameter);
x+= width;
}// end of for loop
if( page.getColor() == c1)
page.setColor(c2);
else
page.setColor(c1);
y+= width;
}//end of for loop
int n = 150; // wait n milliseconds
try { Thread.sleep (n); }
catch (InterruptedException e) {}
}// end of paint
public Color mixColor(){
Color c = new Color (
(int)(Math.random () * 256), // red = 0..255
(int)(Math.random () * 256), // green = 0..255
(int)(Math.random () * 256)); // blue = 0..255
return c;
}
}// end of applet
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -