Dark Bit Factory & Gravity
ARCHIVE => Archive => Java,JS & Flash => Topic started by: combatking0 on May 03, 2009
-
Because certain other languages I'm used to currently lack features I require, I'm building a semi-complicated Java Applet to listen to the audio input (either mic or line-in) of a computer, store 0.5 seconds of data, analyze it, and return a string.
I'm having difficulty setting up a repeating counter, which should be called every 0.1 of a second. This is just a test.
Here is my code: (indented with tabs, but they haven't shown up on here)import java.applet.*;
import java.net.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*; // for ByteArrayOutputStream
import javax.sound.sampled.*;
public class test3 extends Applet{
public void init(){
boolean stopCapture=false;
ByteArrayOutputStream byteArrayOutputStream; // Might want to set this as a normal array
TargetDataLine targetDataLine; // Does this select the audio input?
AudioInputStream audioInputStream; // Set up an audio input stream?
SourceDataLine sourceDataLine; // Or does this select the audio input?
ActionListener recPoller = new ActionListener();
Timer poller = new Timer(100, recPoller);
poller.start();
// captureAudio(); // Calls the audio capture function
String msg="1";
}
public class dataStore{
int tmr=0;
}
public class something implements ActionListener{
public void actionPerformed(ActionEvent event){
try{
//getAppletContext().showDocument(new URL("javascript:doAlert(\"" + dataStore.tmr +"\")"));
//dataStore.tmr++;
}catch(MalformedURLException me){}
}
}
private void captureAudio(){
try{
// Write something later to catch audio data
}catch(Exception e){}
}
}
I keep getting an error saying
"test3.java:17: java.awt.event.ActionListener is abstract; cannot be instantiated"
Does anybody know what this means or how to fix it?
SUN -> :whack: <- me
-
I guess this line is wrong:
ActionListener recPoller = new ActionListener();
You already declared the class something. Why not instantiate it instead of the
abstract interface ActionListener ? So, maybe if you replace it with the following line
something recPoller = new something();
Maybe this helps out.
-
The idea of an Abstract class is that it doesn't have any implementation (i.e. no code), it is just a template. When you make your own class that inherits from it:
public class MyListener implements ActionListener (is that the right java syntax Benny?)
then you will be forced to implement all the methods in the template in your own class. i.e. you must override every member of the class.
So Benny's suggestion is absolutely correct, you want to be working with the derived class not the base class.
Jim
-
Excellent - that works :) K+
I was using an example adapted from another website, but only having experience with object based languages and not object orientated languages is a bit of a hinderence for me.
I'm starting to understand how Java works now.
-
Keep asking questions, CK0. Java is a good language to learn
the object orientated paradigma.
Glad that we could help.
-
Thanks bennny!
I'll now see if I can run a check every 0.1 of a second to see if the input signal saturates. I would do it in real time, but apparently it is not currently possible.
Once the signal saturates, I'll then need to record the next 0.5 seconds of signal into a numerical array for further processing.
I've found a suitable page regarding the sound API (http://www.developer.com/java/other/article.php/2105421). I'll try to re-use the relevant code chunks and come back when it doesn't quite work.
-
Sounds good. Good luck, mate!