import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;
import java.net.*;
import javax.swing.*;/*
<applet code="URLGetAudioDemo.class" width="300" height="300">
</applet>
*/public class AppletTest extends JFrame
{
public AppletTest()
{
Applet applet = new App();
applet.init();
this.add( applet );
this.setSize( 260, 130 );
this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
this.setVisible( true );
applet.start();
}
private class App extends JApplet implements ActionListener
{
AudioClip ac; Button button_play, button_loop, button_stop;
public void init()
{
this.setSize(260, 130);
this.setLayout( new FlowLayout() );
ac = this.getAudioClip( getCodeBase(), "Ring.wav" );
Label label = new Label("远程音乐载入成功!点击按钮开始播放!");
this.add(label);
button_play = new Button("开始播放");
button_loop = new Button("循环播放");
button_stop = new Button("停止播放");
button_play.addActionListener(this);
button_stop.addActionListener(this);
button_loop.addActionListener(this);
this.add(button_play);
this.add(button_loop);
this.add(button_stop);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == button_play)
{
ac.play();
}
else if (e.getSource() == button_loop)
{
ac.loop();
}
if (e.getSource() == button_stop)
{
ac.stop();
}
}
}
public static void main( String[] args )
{
new AppletTest();
}
}上面这段代码为什么运行时出现空指针异常?
解决方案 »
- 关于java中异常处理的问题
- 在一个JFramme窗口上弹出一个模态的对话框,父窗口会不可操作。在这种情况下,鼠标在父窗口上移动,我想得到鼠标在父窗口的Pane上的位置!
- 一个IO问题
- 高分请教一下JAVA里面的原子操作实现
- AbstractList.this.remove(lastRet) 中的AbstractList.this是什么含义,他是在调用哪个类的remove方法
- javax.comm串口通信无法发送数据
- 问题: 在JPanel上由鼠标可以添加TextArea, 可以随意拖动.
- 关于jgraph的放大缩小问题
- 连接数据库的错误!!!
- ※※※※java rmi 编程的问题!※※※※※※
- 两上LIST的值如何进行运算,返回另一个结果LIST
- 关于窗口边框
把歌曲放在这个目录下应该可以的