做了个窗口,想在里面添加背景音乐,请问怎么做? 做了个窗口,想在里面添加背景音乐,请问怎么做?急救! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /****************************************************************** * Beginning Java 5 Game Programming * by Jonathan S. Harbour * PlayMusic program ******************************************************************/import java.awt.*;import java.applet.*;import java.io.*;import java.net.*;import javax.sound.midi.*;public class PlayMusic extends Applet { String filename = "titlemusic.mid"; Sequence song; private URL getURL(String filename) { URL url = null; try { url = new java.net.URL(getCodeBase() + filename); } catch (MalformedURLException e) { e.printStackTrace(); } return url; } //initialize the applet public void init() { try { song = MidiSystem.getSequence(getURL(filename)); Sequencer sequencer = MidiSystem.getSequencer(); sequencer.setSequence(song); sequencer.open(); sequencer.start(); } catch (InvalidMidiDataException e) { } catch (MidiUnavailableException e) { } catch (IOException e) { } } //repaint the applet window public void paint(Graphics g) { int x=10, y = 1; if (song != null) { g.drawString("Midi File: " + filename, x, 15 * y++); g.drawString("Resolution: " + song.getResolution(), x, 15 * y++); g.drawString("Tick length: " + song.getTickLength(), x, 15 * y++); g.drawString("Tracks: " + song.getTracks().length, x, 15 * y++); g.drawString("Patches: " + song.getPatchList().length, x, 15 * y++); } else { g.drawString("Error loading sequence file " + filename, 10, 15); } }}这是一本JAVA游戏编程书上的源代码,可以载入MIDI文件。public void paint 方法,楼主应该不用,自己删掉吧。 纠错!!!! struts中删除上传的文件 Java中直接Copy文件的方法 有会的朋友指导下吗 刚学JAVA 拜托了 UTF-8存储中文的问题~~乱码的问题 菜鸟一个线程问题 请问:用JOptionPane.showInputDialog等生成的对话框的字体大小和颜色等要怎么改变? 如何控制下拉框输入长度和输入字符 送分啦:Jbuilder4的序列号 Java ServerSocket编程,我为什么接收不到数据? 高分,请问各位大侠,哪位有李兴华老师上课的J2SE的上课笔记? 谁帮我讲讲这篇代码时间监听那段程序?
* Beginning Java 5 Game Programming
* by Jonathan S. Harbour
* PlayMusic program
******************************************************************/import java.awt.*;
import java.applet.*;
import java.io.*;
import java.net.*;
import javax.sound.midi.*;public class PlayMusic extends Applet { String filename = "titlemusic.mid";
Sequence song; private URL getURL(String filename) {
URL url = null;
try {
url = new java.net.URL(getCodeBase() + filename);
}
catch (MalformedURLException e) { e.printStackTrace(); }
return url;
} //initialize the applet
public void init() {
try {
song = MidiSystem.getSequence(getURL(filename));
Sequencer sequencer = MidiSystem.getSequencer();
sequencer.setSequence(song);
sequencer.open();
sequencer.start(); } catch (InvalidMidiDataException e) {
} catch (MidiUnavailableException e) {
} catch (IOException e) { }
} //repaint the applet window
public void paint(Graphics g) {
int x=10, y = 1;
if (song != null) {
g.drawString("Midi File: " + filename, x, 15 * y++);
g.drawString("Resolution: " + song.getResolution(), x, 15 * y++);
g.drawString("Tick length: " + song.getTickLength(), x, 15 * y++);
g.drawString("Tracks: " + song.getTracks().length, x, 15 * y++);
g.drawString("Patches: " + song.getPatchList().length, x, 15 * y++);
} else {
g.drawString("Error loading sequence file " + filename, 10, 15);
}
}}这是一本JAVA游戏编程书上的源代码,可以载入MIDI文件。public void paint 方法,楼主应该不用,自己删掉吧。