我最近写了一个JApplet程序,播放wav音频的。但只能播放一个,它有125K,其他两个都超过了400k,请问是大小的限制导致了另外两个不能播放吗?

解决方案 »

  1.   

    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;public class AudioPlayer extends JApplet {
    private AudioClip[] sounds; private AudioClip currentSound; // 当前歌曲 private JButton playSound, loopSound, stopSound; private JComboBox chooseSound; public void init() {
    Container c = getContentPane();
    c.setLayout(new FlowLayout());
    String choices[] = { "call.wav", "tiaopi.wav", "ffy.mp3" }; // 歌曲名

    chooseSound = new JComboBox(choices);
    chooseSound.addItemListener(new ItemListener() {
    public void itemStateChanged(ItemEvent e) {
    currentSound.stop();
    currentSound = sounds[chooseSound.getSelectedIndex()];
    }
    });
    c.add(chooseSound);
    ButtonHandler h = new ButtonHandler();
    playSound = new JButton("Play");
    playSound.addActionListener(h);
    c.add(playSound);
    loopSound = new JButton("Loop");
    loopSound.addActionListener(h);
    c.add(loopSound);
    stopSound = new JButton("Stop");
    stopSound.addActionListener(h);
    c.add(stopSound);
    sounds = new AudioClip[choices.length];
    // 加载音频文件,创建AudioClip对象
    for (int i = 0; i < choices.length; i++)
    sounds[i] = getAudioClip(getDocumentBase(), choices[i]);
    currentSound = sounds[0];
    } public void stop() {
    currentSound.stop();
    } private class ButtonHandler implements ActionListener {
    public void actionPerformed(ActionEvent e) {
    if (e.getSource() == playSound)
    currentSound.play(); 
    else if (e.getSource() == loopSound)
    currentSound.loop();
    else if (e.getSource() == stopSound)
    currentSound.stop();
    }
    }
    }
      

  2.   

    程序测试能播放多个的
    AudioClip不支持播放mp3格式的,想要支持可以试试jmf
      

  3.   

    呵呵 我忘了删掉mp3格式的文件了,原来是只能播放一个wav,现在好了!谢啦!
      

  4.   

    最近写了一个用户验证密码的程序,其功能如下:
    输入用户名和密码,然后提交,只有在密码位数大于8位切有数字的时候,才输出Thank you Your password meets the security policy 否则输出Sorry Your password does not meet the security policy 可是我的不知道怎么了,两个竟然同时输出了!各位大虾帮帮忙啊!谢啦!login.html文件如下:
    <html>
    <head><title>A Siple Login Page</title></head>
    <body>
    <p>Please Login:
    <form action=login.jsp method=post>
    <p>User Name:<input type=text name=usernameField>
    <p>Password:<input type=text name=passwordField>
    <p><input type=SUBMIT value=Submit>
    </form>
    </body>
    </html>
    login.jsp文件如下:
    <html>
    <head>
    <title>A Simple Jsp That Verifies Password Policy</title>
    </head>
    <body>
    <%! final static int MIN_PSWD_LEN=8;
    static boolean verifyPasswordLength(String password){
    if(password.length()<MIN_PSWD_LEN)return false;
    return true;
    }static boolean verifyPasswordHasDigit(String password){
    for(int i=0;i<password.length();i++)
    if(Character.isDigit(password.charAt(i))) return true;
    return false;
    }static boolean verifyPasswordPolicy(String password){
    if(verifyPasswordLength(password)&&verifyPasswordHasDigit(password))
    return true;
    else  
    return false;
    }
    %><%String password=request.getParameter(passwordField);
    if(verifyPasswordPolicy(password)){%>
    <p>Thank you
    <p>Your password meets the security policy
    <%}else{%>
    <p>Sorry
    <p>Your password does not meet the security policy
    <p><a href="login.html">Please Try Again</a>
    <%}%>
    </body>
    </html>