Results 1 to 2 of 2
  1. #1
    priyoari293 is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default change java to java applet

    does anyone know how to change this java source into java applet?

    package net;

    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.net.ServerSocket;
    import java.net.Socket;

    import javax.sound.sampled.AudioFormat;
    import javax.sound.sampled.AudioInputStream;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.DataLine;
    import javax.sound.sampled.LineUnavailableException;
    import javax.sound.sampled.Mixer;
    import javax.sound.sampled.SourceDataLine;
    import javax.sound.sampled.TargetDataLine;



    public class sender {
    ServerSocket MyService;
    Socket clientSocket = null;
    BufferedInputStream input;
    TargetDataLine targetDataLine;

    BufferedOutputStream out;
    ByteArrayOutputStream byteArrayOutputStream;
    AudioFormat audioFormat;

    SourceDataLine sourceDataLine;
    byte tempBuffer[] = new byte[10000];

    sender() throws LineUnavailableException{
    try {
    audioFormat = getAudioFormat();
    DataLine.Info dataLineInfo = new DataLine.Info( SourceDataLine.class,audioFormat);
    sourceDataLine = (SourceDataLine)
    AudioSystem.getLine(dataLineInfo);
    sourceDataLine.open(audioFormat);
    sourceDataLine.start();
    MyService = new ServerSocket(500);
    clientSocket = MyService.accept();
    captureAudio();
    input = new BufferedInputStream(clientSocket.getInputStream()) ;
    out=new BufferedOutputStream(clientSocket.getOutputStream( ));

    while(input.read(tempBuffer)!=-1){
    sourceDataLine.write(tempBuffer,0,10000);
    }
    } catch (IOException e) {

    e.printStackTrace();
    }

    }
    private AudioFormat getAudioFormat(){
    float sampleRate = 8000.0F;
    int sampleSizeInBits = 16;
    int channels = 1;
    boolean signed = true;
    boolean bigEndian = false;
    return new AudioFormat(
    sampleRate,
    sampleSizeInBits,
    channels,
    signed,
    bigEndian);
    }
    public static void main(String s[]) throws LineUnavailableException{
    sender s2=new sender();
    }


    private void captureAudio() {
    try {

    Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
    System.out.println("Available mixers:");
    for (int cnt = 0; cnt < mixerInfo.length; cnt++) {
    System.out.println(mixerInfo[cnt].getName());
    }
    audioFormat = getAudioFormat();

    DataLine.Info dataLineInfo = new DataLine.Info(
    TargetDataLine.class, audioFormat);

    Mixer mixer = AudioSystem.getMixer(mixerInfo[3]);

    targetDataLine = (TargetDataLine) mixer.getLine(dataLineInfo);

    targetDataLine.open(audioFormat);
    targetDataLine.start();

    Thread captureThread = new CaptureThread();
    captureThread.start();
    } catch (Exception e) {
    System.out.println(e);
    System.exit(0);
    }
    }

    class CaptureThread extends Thread {

    byte tempBuffer[] = new byte[10000];

    public void run() {
    try {
    while (true) {
    int cnt = targetDataLine.read(tempBuffer, 0,
    tempBuffer.length);
    out.write(tempBuffer);
    }

    } catch (Exception e) {
    System.out.println(e);
    System.exit(0);
    }
    }
    }

    }

    i got this source from javasolution.blogspot.com

    this has 2 source but i just add 1, this for voice transmission or voice chat.
    if anyone know voice chat uinsg applet please give me a clue.
    sorry my english bad.
    thank

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    There is nothing in that source that is even remotely GUI-like so there is no way to automatically "change it into an applet" other than your studying the tutorials to learn how to create applets and then write the code yourself. We wish you much luck.

Similar Threads

  1. applet class inside java.applet.* or java.awt.*
    By Manish87 in forum Java Applets
    Replies: 1
    Last Post: 09-27-2010, 03:15 PM
  2. Change Applet to Swing
    By aryowap in forum AWT / Swing
    Replies: 4
    Last Post: 07-08-2010, 10:03 PM
  3. How can I change webpage by applet?
    By fantasyme in forum Java Applets
    Replies: 10
    Last Post: 04-23-2010, 08:24 PM
  4. How to A, B C, D, E,F change to 5,4,3,2,1,0 java
    By theseven in forum New To Java
    Replies: 1
    Last Post: 02-12-2010, 02:48 PM
  5. Replies: 4
    Last Post: 02-22-2009, 07:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •