Hello,
The following custom class has compiler errors where it is not recognizing KeyListener.
Any idea on why I am getting this error?
import java.util.concurrent.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class worker1 extends Thread {
private SynchronousQueue<Object> q;
private int i;
public worker1(SynchronousQueue<Object> q) {
super("Worker 1");
this.q = q;
setFocusable(true);
addKeyListener(
new KeyAdapter()
{
public void keyTyped(KeyEvent event)
{
i++;
}
}
);
}
public void run() {
try {
while(i <= 10) {
System.out.println ( i + " " + Thread.currentThread().getName());
}
q.put(new Object());
q.take();
for(int i =1001; i <= 2000; ++i) {
System.out.println ( i + " " + Thread.currentThread().getName());
}
q.put(new Object());
} catch (InterruptedException e) {
}
}
}
Thank you!