音乐剪辑java代码 java编曲( 五 )


this.getContentPane().add(butzhantin);
this.getContentPane().add(butxia);
try {
UIManager.setLookAndFeel("org.jvnet.substance.skin.SubstanceOfficeBlue2007LookAndFeel");
} catch (ClassNotFoundException e)
{
e.printStackTrace();
} catch (InstantiationException e)
{
e.printStackTrace();
} catch (IllegalAccessException e)
{
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e)
{
e.printStackTrace();
}
setSize(450,450);
systemTray = SystemTray.getSystemTray();//获得系统托盘的实例
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
try {
trayIcon = new TrayIcon(ImageIO.read(new File("004.jpg")));
systemTray.add(trayIcon);//设置托盘的图标,0.gif与该类文件同一目录
}
catch (IOException e1)
{
e1.printStackTrace();
}
catch (AWTException e2)
{
e2.printStackTrace();
}
this.addWindowListener(
new WindowAdapter(){
public void windowIconified(WindowEvent e)
{
dispose();//窗口最小化时dispose该窗口
}
});
trayIcon.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e){
if(e.getClickCount() == 2)//双击托盘窗口再现
setExtendedState(Frame.NORMAL);
setVisible(true);
}
});
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if (source== butbofan)
{
System.out.println((String) box1.getSelectedItem());
file1=new File((String) box1.getSelectedItem()+".wav");
butboxhuan.setEnabled(true);
buttinzi.setEnabled(true);
butzhantin.setEnabled(true);
butzhantin.setText("暂停");
try {
sound1 = Applet.newAudioClip(file1.toURL());
chosenClip = sound1;
} catch(OutOfMemoryError er){
System.out.println("内存溢出");
er.printStackTrace();
} catch(Exception ex){
ex.printStackTrace();
}
chosenClip.play();
this.setTitle("正在播放"+(String) box1.getSelectedItem());
}
if (source== butboxhuan)
{
file1=new File((String) box1.getSelectedItem()+".wav");
try {
sound1 = Applet.newAudioClip(file1.toURL());
chosenClip = sound1;
} catch(OutOfMemoryError er){
System.out.println("内存溢出");
er.printStackTrace();
} catch(Exception ex){
ex.printStackTrace();
}
looping = true;
chosenClip.loop();
butboxhuan.setEnabled(false);
buttinzi.setEnabled(true);
butzhantin.setText("暂停");
this.setTitle("正在循环播放"+(String) box1.getSelectedItem());
}
if (source== buttinzi)
{
if (looping)
{
looping = false;
chosenClip.stop();
butboxhuan.setEnabled(true);
butzhantin.setText("暂停");
} else {
chosenClip.stop();
}
buttinzi.setEnabled(false);
this.setTitle("停止播放");
}
if(source==butshan)
{
butzhantin.setText("暂停");
}
if(source==butzhantin)
{
buttinzi.setEnabled(false);
butzhantin.setText("继续");
if(source==butzhantin)
{
butzhantin.setText("暂停");
}
}
if(source==butxia)
{
butzhantin.setText("暂停");
}
}
public static void main(String[] args)
{
bofan_2 xx=new bofan_2();
}
}
/*
可以用加载声音文件的方法:
第一?。簃ysound= new Sound();
mysound.attachSound(声音id名字);
ptime = 0;
播放按钮as:
on(release){
mysound.start(ptime);
}
暂停按钮as:
on(release){
ptime = mysound.position/1000;
mysound.stop();
}
*/
【音乐剪辑java代码 java编曲】

推荐阅读