html能跑java吗,为什么能用HTML运行不能用ECLIPSE运行

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

把程序贴上吧。。主要是设置七幅图,每图对应一首歌。有个开始和停止的按钮,还有个选择第几幅图的组合框。。要求选了第几幅图就放对应的歌。。然后有延时器。。。一定延时后进入下一幅图。。

顺带问下。。为什么我设置了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(); }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值