applet动画中怎么加组件?
以下是一个applet动画程序,我想在里面加个JButton 高手帮帮忙,应该怎么加呀? 谢谢了哦 import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.swing.*;
public class NationDay extends java.applet.Applet implements Runnable {
MediaTracker tracker = null;
int frame_x = 0;
boolean bz_load = false;
boolean bz_anima = false;
int current = 0;
private boolean init = false;
private AudioClip m_Audio;
Image backImage = null;
Image myImage = null;
Image allImages[] = null;
Thread animation = null;
public void init() {
if(init == false){
tracker = new MediaTracker(this);
allImages = new Image[7];
for(int x=0;x<7;x++)
allImages[x] = getImage(getDocumentBase(),"Image/Mrab0"+x+".gif");
for(int x=0;x<7;x++)
tracker.addImage(allImages[x],x);
backImage = getImage(getDocumentBase(),"Image/50.gif");
}
}
//开始动画
public void paint(Graphics g){
setBackground(Color.WHITE);
bz_load = true;
if(bz_load){
bz_anima = true;
g.drawImage(backImage,0,0,this);
g.drawImage(allImages[current],frame_x,0,this);
}
else{
g.drawString("画面载入中,请稍候......",0,20);
}
}
public void start(){
m_Audio = getAudioClip(getDocumentBase(),"Image/spacemusic.au");
if(m_Audio != null){
m_Audio.loop();
if(animation == null){
animation = new Thread(this);
animation.start();
}
}
}
public void stop(){
if(m_Audio != null)
m_Audio.stop();
if(animation != null){
animation.stop();
animation = null;
}
}
//反复播放动画
public void run(){
while(!checkroll())
sleep(100);
bz_load = true;
while(true){
roll(0,this.getSize().width-42);
}
}
boolean checkroll(){
boolean finished = true;
for(int i=0;i<7;i++){
if((tracker.statusID(i,true)&MediaTracker.COMPLETE) == 0)
finished = false;
}
return finished;
}
void roll(int begin,int end){
if(begin<end){
for(int x=begin;x<=end;x+=21){
frame_x = x;
repaint();
current--;
if(current == -1)
current = 3;
sleep(150);
}
}
else{
for(int x=begin;x>=end;x-=21){
frame_x = x;
repaint();
current++;
if(current == 7)
current = 0;
sleep(150);
}
}
}
public void sleep(int a){
try{
Thread.sleep(a);
}
catch(InterruptedException e){
}
}
public void update(Graphics g){
g.clipRect(0,0,1000,500);
paint(g);
}
}
----------------解决方案--------------------------------------------------------