java applet为什么未初始化小程序
mportjava.awt.event.*;importjava.net.*;importjava.awt.*;importjava.applet.*;publiccla...
mport java.awt.event.*;
import java.net.*;
import java.awt.*;
import java.applet.*;
public class Show extends Applet implements ActionListener{
String once="file:/D:/QQ/Misc/Sound/Classic/shake.wav";
String lo="file:/C:/Documents and Settings/Administrator/桌面/未命名.gif";
AudioClip onceClip;
Image im;
Button playOnce;
Button stopOnce;
Button playLoop;
Button stopLoop;
boolean playing=false;
boolean looping=false;
public void init() {
try{
onceClip=getAudioClip(new URL(once));
im=getImage(new URL(lo));
}catch(MalformedURLException e){
}
playOnce=new Button("play");
stopOnce=new Button("stop");
stopOnce.setEnabled(false);
playLoop=new Button("show");
stopLoop=new Button("hold");
stopLoop.setEnabled(false);
playOnce.addActionListener(this);
add(playOnce);
stopOnce.addActionListener(this);
add(stopOnce);
playLoop.addActionListener(this);
add(playLoop);
stopLoop.addActionListener(this);
add(stopLoop);
}
public void stop(){
if(playing){
onceClip.stop();
}
}
public void start(){
if(playing){
onceClip.play();
}
}
public void paint(Graphics g) {
if(looping){
g.drawImage(im, 0, 0,this );
}
}
public void actionPerformed(ActionEvent event){
Object source= event.getSource();
if(source==playOnce){
playing=true;
onceClip.loop();
stopOnce.setEnabled(true);
playOnce.setEnabled(false);
return ;
}
if(source==stopOnce){
playing=false;
onceClip.stop();
stopOnce.setEnabled(false);
playOnce.setEnabled(true);
return ;
}
if(source==playLoop){
playing=true;
stopOnce.setEnabled(true);
playOnce.setEnabled(false);
return ;
}
if(source==stopLoop){
playing=false;
stopOnce.setEnabled(false);
playOnce.setEnabled(true);
return ;
}
}
} 展开
import java.net.*;
import java.awt.*;
import java.applet.*;
public class Show extends Applet implements ActionListener{
String once="file:/D:/QQ/Misc/Sound/Classic/shake.wav";
String lo="file:/C:/Documents and Settings/Administrator/桌面/未命名.gif";
AudioClip onceClip;
Image im;
Button playOnce;
Button stopOnce;
Button playLoop;
Button stopLoop;
boolean playing=false;
boolean looping=false;
public void init() {
try{
onceClip=getAudioClip(new URL(once));
im=getImage(new URL(lo));
}catch(MalformedURLException e){
}
playOnce=new Button("play");
stopOnce=new Button("stop");
stopOnce.setEnabled(false);
playLoop=new Button("show");
stopLoop=new Button("hold");
stopLoop.setEnabled(false);
playOnce.addActionListener(this);
add(playOnce);
stopOnce.addActionListener(this);
add(stopOnce);
playLoop.addActionListener(this);
add(playLoop);
stopLoop.addActionListener(this);
add(stopLoop);
}
public void stop(){
if(playing){
onceClip.stop();
}
}
public void start(){
if(playing){
onceClip.play();
}
}
public void paint(Graphics g) {
if(looping){
g.drawImage(im, 0, 0,this );
}
}
public void actionPerformed(ActionEvent event){
Object source= event.getSource();
if(source==playOnce){
playing=true;
onceClip.loop();
stopOnce.setEnabled(true);
playOnce.setEnabled(false);
return ;
}
if(source==stopOnce){
playing=false;
onceClip.stop();
stopOnce.setEnabled(false);
playOnce.setEnabled(true);
return ;
}
if(source==playLoop){
playing=true;
stopOnce.setEnabled(true);
playOnce.setEnabled(false);
return ;
}
if(source==stopLoop){
playing=false;
stopOnce.setEnabled(false);
playOnce.setEnabled(true);
return ;
}
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询