Author Topic: [JAVA] Applet which repeats and counts.  (Read 6075 times)

0 Members and 1 Guest are viewing this topic.

Offline combatking0

  • JavaScript lives!
  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4569
  • Karma: 235
  • Retroman!
    • View Profile
    • Combat King's Barcode Battler Home
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)
Code: [Select]
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
You are our 9001st visitor.
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: [JAVA] Applet which repeats and counts.
« Reply #1 on: May 03, 2009 »
I guess this line is wrong:

Code: [Select]
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

Code: [Select]
something recPoller = new something();
Maybe this helps out.
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: [JAVA] Applet which repeats and counts.
« Reply #2 on: May 03, 2009 »
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
Challenge Trophies Won:

Offline combatking0

  • JavaScript lives!
  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4569
  • Karma: 235
  • Retroman!
    • View Profile
    • Combat King's Barcode Battler Home
Re: [JAVA] Applet which repeats and counts.
« Reply #3 on: May 04, 2009 »
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.
You are our 9001st visitor.
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: [JAVA] Applet which repeats and counts.
« Reply #4 on: May 04, 2009 »
Keep asking questions, CK0. Java is a good language to learn
the object orientated paradigma.

Glad that we could help.
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline combatking0

  • JavaScript lives!
  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4569
  • Karma: 235
  • Retroman!
    • View Profile
    • Combat King's Barcode Battler Home
Re: [JAVA] Applet which repeats and counts.
« Reply #5 on: May 04, 2009 »
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. I'll try to re-use the relevant code chunks and come back when it doesn't quite work.
You are our 9001st visitor.
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: [JAVA] Applet which repeats and counts.
« Reply #6 on: May 05, 2009 »
Sounds good. Good luck, mate!
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won: