JButton声音效果 我想问一下,在一个JButton上操作,当鼠标经过一个JButton上时会发一个声音的效果(如:一水滴声),这个效果怎么搞去来,希望高人指点一下,谢谢。。给出相应的代码。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 package com.org.timer;import java.awt.Container;import java.awt.FlowLayout;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import javax.swing.JButton;import javax.swing.JFrame;import sun.audio.AudioPlayer;import sun.audio.AudioStream;public class ButtonSound extends JFrame implements MouseListener { //加入 serialVersionUID 防止警告错误 没什么特殊意义 private static final long serialVersionUID = 1L; private JButton mybuttion; private Container content; public ButtonSound() { // 设置版面位置 1024*768 居中 this.setLayout(new FlowLayout()); this.setBounds(412, 294, 200, 120); this.setResizable(false); content = this.getContentPane(); content.setLayout(null); mybuttion = new JButton("音乐按钮"); mybuttion.setBounds(50, 30, 100, 30); mybuttion.addMouseListener(this); this.add(mybuttion); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } //播放声音的方法 public void palySound() { AudioStream as = null; FileInputStream inStreamObj = null; try { //C:/WINDOWS/Media/Windows XP 启动.wav //这个路径是 windows XP 默认的开机音乐的路径 //有需要 可以自己改 但是JAVA支持的音乐文件只有 .wav .au .MIDI //等格式 不要拿MP3等文件 inStreamObj = new FileInputStream("C:/WINDOWS/Media/Windows XP 启动.wav"); as = new AudioStream(inStreamObj); } catch (FileNotFoundException e) { } catch (IOException e) { } AudioPlayer.player.start(as); } public void mouseClicked(MouseEvent e) { // 鼠标单击事件 } public void mouseEntered(MouseEvent e) { // 移动到 也就是我们需要的 palySound(); } public void mouseExited(MouseEvent e) { // 移动开 } public void mousePressed(MouseEvent e) { // 按下 } public void mouseReleased(MouseEvent e) { // 释放 } public static void main(String[] args) { new ButtonSound(); }}-------------------------------------------很完美 给分吧 好像sum发布了个支持mp3格式的包的! 我想因该要,WAV都可以放了,MP3的也可以的,同一个性质的,只是没有找到。。 对象 关联问题 是不是用j2ee和j2me可以实现的用j2se都可以实现? 读取oracle中的byte[]字段 转化为word文件 程序写了一半下面该怎么写啊 请高手帮帮忙,怎样同过DatabaseMetaData 获得系统的存储过程 深入讨论reference 高手请来指点 急需一JAVA设计的电子白板!!!急急急!!! 从网上下载的很多大软件都是 *.rpm *.iso格式的谁知道怎么用???up有分! 急救!!!java 高手请进! 中国队赢球,特来送分给java的各位兄弟!!!(只限前10名) 如何构造一个循环的链表? 新手求教个程序小问题~~~~~~~~~~~~
import java.awt.FlowLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;import javax.swing.JButton;
import javax.swing.JFrame;import sun.audio.AudioPlayer;
import sun.audio.AudioStream;public class ButtonSound extends JFrame implements MouseListener {
//加入 serialVersionUID 防止警告错误 没什么特殊意义
private static final long serialVersionUID = 1L;
private JButton mybuttion;
private Container content; public ButtonSound() {
// 设置版面位置 1024*768 居中
this.setLayout(new FlowLayout());
this.setBounds(412, 294, 200, 120);
this.setResizable(false); content = this.getContentPane();
content.setLayout(null); mybuttion = new JButton("音乐按钮");
mybuttion.setBounds(50, 30, 100, 30);
mybuttion.addMouseListener(this);
this.add(mybuttion); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true); }
//播放声音的方法
public void palySound() {
AudioStream as = null;
FileInputStream inStreamObj = null;
try {
//C:/WINDOWS/Media/Windows XP 启动.wav
//这个路径是 windows XP 默认的开机音乐的路径
//有需要 可以自己改 但是JAVA支持的音乐文件只有 .wav .au .MIDI
//等格式 不要拿MP3等文件
inStreamObj = new FileInputStream("C:/WINDOWS/Media/Windows XP 启动.wav");
as = new AudioStream(inStreamObj);
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
AudioPlayer.player.start(as);
} public void mouseClicked(MouseEvent e) {
// 鼠标单击事件 } public void mouseEntered(MouseEvent e) {
// 移动到 也就是我们需要的
palySound(); } public void mouseExited(MouseEvent e) {
// 移动开 } public void mousePressed(MouseEvent e) {
// 按下 } public void mouseReleased(MouseEvent e) {
// 释放 } public static void main(String[] args) {
new ButtonSound();
}}
-------------------------------------------
很完美 给分吧