📄
字号:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Boy extends Applet implements Runnable,ActionListener
{
final int number=8;
int count=0;
boolean move=true;
Thread mythread;
Button startPlay,stopPlay,continuePlay;
Image[] pic=new Image[number];
public void init()
{
for(int i=0;i<number;i++)
{
pic[i]=getImage(getCodeBase(),"tom"+i+".jpg");
}
mythread=new Thread(this);
startPlay=new Button("开始播放");
stopPlay=new Button("暂停播放");
continuePlay=new Button("继续播放");
startPlay.addActionListener(this);
stopPlay.addActionListener(this);
continuePlay.addActionListener(this);
add(startPlay);
add(stopPlay);
add(continuePlay);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==startPlay)
{
if(!(mythread.isAlive()))
{
mythread=new Thread(this);
mythread.start();
}
}
else if(e.getSource()==stopPlay)
{
move=false;
}
else if(e.getSource()==continuePlay)
{
move=true;
resumeThread();
}
}
public void run()
{
for(count=0;count<number;count++)
{
repaint();
try{
mythread.sleep(800);
}
catch(InterruptedException e){}
while(move==false)
{
try{
hangThread();
}
catch(InterruptedException e1)
{
}
}
}
if(count>=number)
{
repaint();
}
}
public synchronized void hangThread() throws InterruptedException
{
wait();
}
public synchronized void resumeThread()
{
notifyAll();
}
public void paint(Graphics g)
{
if(count<number&&(pic[count])!=null)
g.drawImage(pic[count],10,10,120,80,this);
if(count>=number)
{
g.drawString("播放完毕",60,160);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -