|
How to add a status bar with
a msg using applet?
Use this code: This code will display msg "Key Down" in the status bar when you press any key (except function keys) and "Key Up" when you release the key. import java.awt.*; import java.awt.event.*; import java.applet.*; /* <applet code="SimpleKey" width=300 height=100> </applet> */
public class SimpleKey extends Applet implements KeyListener { String msg=""; int x=10,y ; //output coordinates
public void init() { addKeyListener(this); requestFocus();//request input focus }
public void keyPressed(KeyEvent ke) { showStatus("Key Down"); }
public void keyReleased(KeyEvent ke) { showStatus("Key Up"); }
public void keyTyped(KeyEvent ke) { msg+=ke.getKeyChar(); repaint(); }
//Display Keystrokes public void paint(Graphics g) { g.drawString(msg,x,y); } } |
|
See also
Do you have a Java Problem?
Java Books
Return to : Java Programming Hints and Tips All the site contents are Copyright © www.erpgreat.com
and the content authors. All rights reserved.
|