The
applet below responds to mouse but not to keyboard. What is the problem ?
Thanks in advance
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class PacMan1 extends Applet {
private int x_cd, y_cd;
public void init() {
x_cd = 10;
y_cd = 20;
setEnabled(true);
setForeground(Color.yellow);
setBackground(Color.lightGray);
addMouseListener( new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
System.out.println( "Inside the mouse Clicked" );
if (evt.getID() == MouseEvent.MOUSE_CLICKED) {
x_cd = evt.getX();
y_cd = evt.getY();
}
repaint();
}
});
addKeyListener( new KeyAdapter() {
public void KeyPressed(KeyEvent evt) {
char keyPressed;
System.out.println ( "Inside the process key event" );
keyPressed = evt.getKeyChar();
if (evt.getID() == KeyEvent.KEY_TYPED) {
switch (keyPressed) {
case 'R':
x_cd++;
break;
case 'L':
x_cd--;
break;
case 'T':
y_cd++;
break;
case 'B':
y_cd--;
break;
}
// End swtich
repaint();
}
}
});
}
public void paint(Graphics g) {
System.out.println( "Inside paint" );
g.fillArc(x_cd, y_cd, 50, 50, 45, 300);
}
/*public void update(Graphics g) {
System.out.println( "Inside update" );
paint(g);
}*/
}