求一代码(在面板上实现播放声音和显示gif动画)

windwlr 2004-09-12 12:28:40
哪位大侠帮小弟写一个继承JPanel的类,要求能播放声音,并且能在面板上显示gif动画。高分相送!!!
...全文
224 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
windwlr 2004-09-13
  • 打赏
  • 举报
回复
up
lukan 2004-09-12
  • 打赏
  • 举报
回复
给你一段applet的吧
/*
* @(#)SimplePlayer.java 1.0 04/09/12
*
* You can modify the template of this file in the
* directory ..\JCreator\Templates\Template_2\Project_Name.java
*
* You can also create your own project template by making a new
* folder in the directory ..\JCreator\Template\. Use the other
* templates as examples.
*
*/

//<applet code=SimplePlayer1 width=200 height=50>
//</applet>


import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.net.*;
import java.applet.*;
import java.applet.Applet;

public class SimplePlayer extends JApplet
{
AudioClip audio1;
JLabel playtitle=new JLabel("---------------PlaySound--------------");
JButton
button1=new JButton("Play"),
button2=new JButton("Stop"),
button3=new JButton("Repeat");
JPanel panel=new JPanel();
class Button1Listner implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
audio1.play();
}
}
class Button2Listner implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
audio1.stop();
}
}
class Button3Listner implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
audio1.loop();
}
}
Button1Listner a1=new Button1Listner();
Button2Listner a2=new Button2Listner();
Button3Listner a3=new Button3Listner();

public void init()
{
button1.addActionListener(a1);
button2.addActionListener(a2);
button3.addActionListener(a3);

Container cp=getContentPane();

cp.setLayout(new GridLayout(3,3));
audio1=this.getAudioClip(this.getCodeBase(),"tada.wav");

Component c=new Component(){
public void paint(Graphics g){
super.paint(g);
ImageIcon i=new ImageIcon("a.gif");
i.paintIcon(this,g,0,0);
}
};
cp.add(c);
cp.add(playtitle);
cp.add(button1);
cp.add(button2);
cp.add(button3);

}
}
mbl 2004-09-12
  • 打赏
  • 举报
回复
看看JAVA书,或去网上查

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧