家政网站怎么做/优化是什么意思
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
把程序贴上吧。。主要是设置七幅图,每图对应一首歌。有个开始和停止的按钮,还有个选择第几幅图的组合框。。要求选了第几幅图就放对应的歌。。然后有延时器。。。一定延时后进入下一幅图。。
顺带问下。。为什么我设置了7个对应延时,却都是以第一个为准。。就是第一幅图延迟为多少。。后面就是多少。。
import javax.swing.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class 多媒体动画 extends JApplet{
private final static int NUMBER=7;
private int current=0;
private ImageIcon[] icons=new ImageIcon[NUMBER];
private AudioClip[] au=new AudioClip[NUMBER];
private AudioClip currentAudioClip;
private int[] delays={500000,5000,500000,500000,500000,500000,500000};
private Timer timer=new Timer(delays[0],new TimerListener());
private JLabel jlb=new JLabel();
private JButton jbtResume=new JButton("开始");
private JButton jbtSuspend=new JButton("停止");
private JComboBox jcboNations=new JComboBox(new Object[]{"一号","二号","三号","四号","五号","六号","七号"});
public 多媒体动画(){
for(int i=0;i
icons[i]=new ImageIcon(getClass().getResource(i+".jpg"));
au[i]=Applet.newAudioClip(getClass().getResource(i+".wav"));
}
JPanel panel=new JPanel();
panel.add(jbtResume);
panel.add(jbtSuspend);
panel.add(new JLabel("选择"));
panel.add(jcboNations);
add(jlb,BorderLayout.CENTER);
add(panel,BorderLayout.SOUTH);
jbtResume.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
start();
}
});
jbtSuspend.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
stop();
}
});
jcboNations.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
stop();
current=jcboNations.getSelectedIndex();
presentNation(current);
timer.start();
}
});
timer.start();
jlb.setIcon(icons[0]);
jlb.setHorizontalAlignment(JLabel.CENTER);
currentAudioClip=au[0];
currentAudioClip.play();
}
private class TimerListener implements ActionListener{
public void actionPerformed(ActionEvent e){
current=(current+1)%NUMBER;
presentNation(current);
}
}
private void presentNation(int index){
jlb.setIcon(icons[index]);
jcboNations.setSelectedIndex(index);
currentAudioClip=au[index];
currentAudioClip.play();
timer.setDelay(delays[index]);
}
public void start(){
timer.start();
currentAudioClip.play();
}
public void stop(){
timer.stop();
currentAudioClip.stop(); }
}