简体   繁体   English

小程序未运行

[英]applet is not running

I have a applet which is running perfectly when I am running from eclipse but when I am adding this .java file as a .class it was not running properly.Not even thorough any error. 我有一个小程序,当我从Eclipse运行时,它运行良好,但是当我将该.java文件作为.class添加时,它运行不正常,甚至没有发生任何错误。

I try to add this class file like 我尝试添加此类文件

<html>
<head>
<title>Sample Applet</title>
</head>
<body>

<applet code=Server.class width=120 height=120></applet>

</body>
</html>

brief description about this class 关于本课程的简要说明

This class is receiving a audio as a byte and transferring to speaker. 此类正在接收音频(作为字节)并传输给扬声器。

Applet code: 小程序代码:

import java.applet.Applet;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.SourceDataLine;

public class Server extends Applet{

    AudioInputStream audioInputStream;
    AudioInputStream ais;
    AudioFormat format;
    boolean status = true;
    int port = 50005;
    int sampleRate = 8000;

    @Override
    public void start(){

        try {
            DatagramSocket serverSocket = new DatagramSocket(50005);

            /**
             * Formula for lag = (byte_size/sample_rate)*2
             * Byte size 9728 will produce ~ 0.45 seconds of lag. Voice slightly broken.
             * Byte size 1400 will produce ~ 0.06 seconds of lag. Voice extremely broken.
             * Byte size 4000 will produce ~ 0.18 seconds of lag. Voice slightly more broken then 9728.
             */

            byte[] receiveData = new byte[5000];

            format = new AudioFormat(sampleRate, 16, 1, true, false);

            while (status == true) {
                DatagramPacket receivePacket = new DatagramPacket(receiveData,
                        receiveData.length);

                serverSocket.receive(receivePacket);

                ByteArrayInputStream baiss = new ByteArrayInputStream(
                        receivePacket.getData());

                ais = new AudioInputStream(baiss, format, receivePacket.getLength());
                toSpeaker(receivePacket.getData());
            }
        } 
        catch (SocketException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
        catch (IOException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        super.start();
    }


//  public static void main(String args[]) throws Exception {
//
//
//
//  }

    public void toSpeaker(byte soundbytes[]) {
        try {

            DataLine.Info dataLineInfo = new DataLine.Info(SourceDataLine.class, format);
            SourceDataLine sourceDataLine = (SourceDataLine) AudioSystem.getLine(dataLineInfo);

            sourceDataLine.open(format);

            FloatControl volumeControl = (FloatControl) sourceDataLine.getControl(FloatControl.Type.MASTER_GAIN);
            volumeControl.setValue(6.0206f);

            sourceDataLine.start();
            sourceDataLine.open(format);

            sourceDataLine.start();

            System.out.println("format? :" + sourceDataLine.getFormat());

            sourceDataLine.write(soundbytes, 0, soundbytes.length);
            System.out.println(soundbytes.toString());
            sourceDataLine.drain();
            sourceDataLine.close();
        } catch (Exception e) {
            System.out.println("Not working in speakers...");
            e.printStackTrace();
        }
    }
}

<applet> tag is not supported in HTML 5. Could that be the issue ? HTML 5不支持<applet>标记。这可能是问题吗? Also, the value of code attribute of applet tag must be in quotes Have a look at the link here: http://www.w3schools.com/tags/tag_applet.asp 另外,applet标签的code属性值必须用引号引起来。请在此处查看链接: http : //www.w3schools.com/tags/tag_applet.asp

The newer way of embedding the applet is shown here: https://eyeasme.com/Shayne/HTML5_APPLETS/ 此处显示了嵌入小程序的新方法: https : //eyeasme.com/Shayne/HTML5_APPLETS/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM