1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | import java.awt.*; import java.awt.event.*; import java.applet.*; /* <applet code="Key" width=300 height=400> </applet> */ public class Key extends Applet implements KeyListener { int X=20,Y=30; String msg="KeyEvents--->"; public void init() { addKeyListener(this); requestFocus(); setBackground(Color.green); setForeground(Color.blue); } public void keyPressed(KeyEvent k) { showStatus("KeyDown"); int key=k.getKeyCode(); switch(key) { case KeyEvent.VK_UP: showStatus("Move to Up"); break; case KeyEvent.VK_DOWN: showStatus("Move to Down"); break; case KeyEvent.VK_LEFT: showStatus("Move to Left"); break; case KeyEvent.VK_RIGHT: showStatus("Move to Right"); break; } repaint(); } public void keyReleased(KeyEvent k) { showStatus("Key Up"); } public void keyTyped(KeyEvent k) { msg+=k.getKeyChar(); repaint(); } public void paint(Graphics g) { g.drawString(msg,X,Y); } } |
Output:

Java Keyboard programe output
Description :
This is the one stop educational site for all Electronic and Computer students. If you want to learn something new then we are here to help. We work on Microcontroller projects, Basic Electronics, Digital electronics, Computer projects and also in basic c/c++ programs.
#Home #Sitemap #Submit #Terms of Use
Copyright©2011 electrofriends.com All Rights Reserved
Contact:info@electrofriends.com | Powered by Dhyeya
October 20th, 2011 at 7:12 pm
I am happy to become right here, this really is my personal first publish,
wish we’ll gradually turn out to be friends!
October 26th, 2011 at 9:39 pm
I’m happy to become right here, this really is my very first publish, wish we will gradually become friends!
December 16th, 2011 at 8:14 pm
this is my personal first publish on the forum and i am
anxious
December 17th, 2011 at 12:05 pm
this ia good program for helping me.
Nakul
December 17th, 2011 at 12:06 pm
this ia good program for helping me for undetrstanding applet for my exam preparetion. Thankx
Nakul
December 23rd, 2011 at 11:23 pm
Doesn’t work.