Java and the Internet: Manipulating the Status Line


When an applet is running inside a web browser - as opposed to, say, inside the "appletviewer" program, you can easily manipulate the status bar of that browser from inside your applet. The status bar is the small display area, usually at the bottom or your window, where your browser displays mesages such as "contacting host...", "retrieving data...", etc.

You applet can put whatever message it likes inside that status line, using the Applet method (see intro):
public void showStatus(String  msg);
Here is a simple example that uses two buttons to display two different message in the status bar of your browser.
import java.applet.Applet;
import java.awt.*;

public class StatusTest extends Applet
{
   private Button msg1 = new Button("Message 1");
   private Button msg2 = new Button("Message 2");

   public void init()
   {
      setLayout(new FlowLayout());
      add(msg1);
      add(msg2);
   }
   public boolean action(Event e, Object o)
   {
      if (e.target == msg1)
         showStatus("Congratulations, you are displaying a message");
      else if (e.target == msg2)
         showStatus("and yes, here is another message !");
      return true;
   }
}
 


In other words, to display a small status line from within an applet, you simply use the method showStatus("whatever string"). That is very nice and easy, and can be very useful. However, you should be aware that your applet is not the only one using that status line. The browser itself may, at any time, need the status line to display some message, or another applet may write its message there. Therefore, the messages on the status line should be considered "temporary" only. You can use the showStatus message to display informative messages, but you should not use it to display an important message - after all, your important messge may be erased at any time by some trivial message that the browser puts there, like "done".

However, since it is so easy to do, most applets should make use of this showStatus method to occasionally display informative messages, especially if an applet loads some data from the internet (in that case, a message such as "loading data, please wait ..." might be useful).


(bgw)