import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.sound.sampled.*;
public class MainClass extends Frame implements ActionListener
{
static final long serialVersionUID = 0;
Label recording = new Label("Recording...");
MainClass()
{
super();
this.setTitle("NISSI v1.0");
this.setLocation(1050, 450);
this.setSize(150, 400);
this.setBounds(1050, 450, 150, 400);
Color bgclr = new Color(200,220,220);
this.setBackground(bgclr);
this.setLayout(null);
Label lbTitle = new Label("NISSI v1.0");
lbTitle.setBounds(40, 40, 100, 20);
lbTitle.setForeground(Color.BLUE);
Label lbIp = new Label("Type in IP-address:");
lbIp.setForeground(Color.BLUE);
lbIp.setBounds(10, 90, 120, 20);
TextField tfIp = new TextField();
tfIp.setBounds(10, 110, 120, 20);
Button btConnect = new Button("Connect");
btConnect.setBounds(5, 170, 70, 30);
Button btDisconnect = new Button("Disconnect");
btDisconnect.setBounds(75, 170, 70, 30);
Button btStartRec = new Button("Talk");
btStartRec.setBounds(5, 280, 70, 30);
btStartRec.addActionListener(this);
btStartRec.setActionCommand("startRec");
Button btStopRec = new Button("Stop");
btStopRec.setBounds(75, 280, 70, 30);
btStopRec.addActionListener(this);
btStopRec.setActionCommand("stopRec");
Button btExit = new Button("EXIT");
btExit.setBounds(75, 350, 70, 30);
btExit.addActionListener(this);
btExit.setActionCommand("exit");
recording.setBounds(10, 300, 100, 30);
this.add(lbTitle);
this.add(lbIp);
this.add(tfIp);
this.add(btConnect);
this.add(btDisconnect);
this.add(btStartRec);
this.add(btStopRec);
this.add(btExit);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
setVisible(false);
dispose();
System.exit(0);
}
});
this.setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
String actionCommand = ae.getActionCommand();
if(actionCommand.equals("exit"))
{
this.setVisible(false);
this.dispose();
System.exit(0);
}
if(actionCommand.equals("startRec"))
{
File outputFile = new File("test.wav");
AudioFormat audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100.0F, 16, 2, 4, 44100.0F, false);
DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat);
TargetDataLine targetDataLine = null;
AudioFileFormat.Type targetType = AudioFileFormat.Type.WAVE;
AudioRecorder recorder = new AudioRecorder(targetDataLine, targetType, outputFile);
try
{
targetDataLine = (TargetDataLine) AudioSystem.getLine(info);
targetDataLine.open(audioFormat);
}
catch(LineUnavailableException e)
{
System.out.println("LineUnavailable");
}
recorder.startRecording();
this.add(recording);
}
if(actionCommand.equals("stopRec"))
{
//recorder.stopRecording();
this.remove(recording);
}
}
public static void main(String[] args)
{
MainClass mc = new MainClass();
}
}