📄 boy.java
字号:
import java.awt.*;
import java.applet.*;
public class boy extends Applet implements Runnable
{
Image offscreenImage;//add a imageobject
Graphics offscreenGraphics;// ADD A GRAPHICS OBJECT
Thread runner;
int i=0;
public void start()
{
setBackground(Color.blue);//
offscreenImage=createImage(this.size().width,this.size().height);//
offscreenGraphics=offscreenImage.getGraphics();//
if (runner==null)
{runner=new Thread(this);
runner.start();
}
}
public void stop()
{
if (runner!=null)
{runner.stop();
runner=null;
}
}
public void mainpart()
{offscreenGraphics.setColor(Color.black);
offscreenGraphics.fillOval(10,10,60,60);
offscreenGraphics.setColor(Color.white);
offscreenGraphics.fillOval(25,30,8,8);
offscreenGraphics.fillOval(50,30,8,8);
offscreenGraphics.drawLine(40,35,40,50);
offscreenGraphics.drawLine(40,70,40,170);}
public void paint(Graphics g)
{
switch (i)
{
case 1:
offscreenGraphics.clearRect(0,0,this.size().width,this.size().height);
mainpart();
offscreenGraphics.drawLine(0,110,80,110);
offscreenGraphics.drawLine (0,230,40,170);
offscreenGraphics.drawLine(40,170,80,230);
//g.drawImage(offscreenImage,0,0,this);
break;
case 0:
offscreenGraphics.clearRect(0,0,this.size().width,this.size().height);
mainpart();
offscreenGraphics.drawLine(0,65,40,110);
offscreenGraphics.drawLine (40,110,80,65);
offscreenGraphics.drawLine(0,210,40,170);
offscreenGraphics.drawLine(40,170,80,210);
//g.drawImage(offscreenImage,0,0,this);
break;
case 2:
offscreenGraphics.clearRect(0,0,this.size().width,this.size().height);
mainpart();
offscreenGraphics.drawLine(0,135,40,110);
offscreenGraphics.drawLine (40,110,80,135);
offscreenGraphics.drawLine(0,220,40,170);
offscreenGraphics.drawLine(40,170,80,220);
//g.drawImage(offscreenImage,0,0,this);
break;
case 3:
offscreenGraphics.clearRect(0,0,this.size().width,this.size().height);
mainpart();
offscreenGraphics.drawLine(15,170,40,110);
offscreenGraphics.drawLine (40,110,65,170);
offscreenGraphics.drawLine (35,250,40,170);
offscreenGraphics.drawLine(40,170,45,250);
break;
default:System.out .println("error");
}
g.drawImage(offscreenImage,0,0,this);
}
public void update(Graphics g)
{
setBackground(Color.blue);//
paint(g); //不清除屏幕
}
public void run()
{
while (runner!=null){//begin of while
//setBackground(Color.blue);
for (i=0;i<4;i+=1)
{ repaint();
try
{Thread.sleep(100);}
catch(InterruptedException e)
{}
}
for (i=3;i>=0;i-=1)
{repaint();
try{Thread.sleep(100);}
catch(InterruptedException e){}
}
}//end of while
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -