Since im a real noob to programming , i was trying to work out this code and i m getting a partial output. The idea was to print the character typed on the applet and if alt or shift key is pressed, it must be displayed in the status bar. The problem is there is no response on the applet but on pressing alt or shift key, i get the appropriate response on the status bar. here is the code:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/* <applet code="MyKeyApplet.class"
width = "400"
height = "400">
</applet>*/
public class MyKeyApplet extends Applet implements KeyListener{
char ch;
String str=" ";
public void init(){
this.addKeyListener(this);
requestFocus();
}
public void keyPressed(KeyEvent k){
int x = k.getKeyCode();
if(x==KeyEvent.VK_SHIFT)
showStatus("You pressed Shift Key");
else if (x==KeyEvent.VK_ALT)
showStatus("You pressed Alt Key");
}
public void paint(Graphics g){
g.drawString(str,40,40);
}
public void keyTyped(KeyEvent k){
ch=k.getKeyChar();
str="You Pressed" + ch;
repaint();
}
public void keyReleased(KeyEvent k){
}
}