Add Status Bar Msg In Applet

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); 

Java Tips

See also
Method Local Inner Class

Do you have a Java Problem?
Ask It in The Java Forum

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.