Status bar Applet showStatus() method Example

Displaying messages is of two ways in Applet. One way is displaying anywhere in the applet window and the other way is displaying in the status bar with showStatus() method.

1. What is status bar?

The bottom of the applet window is known as status bar. In a Browser or MS-Word, the bottom panel is known as status bar where in the line number where the cursor exists, current page number and total number of pages etc. are displayed.

Status bar comes at the bottom of the browser and is used by the browser to display the status of the document opened. The applet can use this status bar to display strings (messages).

2. How to display in status bar?

To display the two ways, the Graphics class comes drawString() method and Applet class comes with showStatus() method. Let us see what API says about these methods.

  • void drawString(String str, int x, int y): Draws the text given by the specified string, using this graphics context’s current font and color. The baseline of the leftmost character is at position (x, y) in this graphics context’s coordinate system.
  • void showStatus(String msg): Requests that the argument string be displayed in the "status window". Many browsers and applet viewers provide such a window, where the application can inform users of its current state.

The following applet draws a string in the applet window (using drawString()) and another string message on the status bar (using showStatus() ).

HTML file: SSD.html

Applet file:

import java.applet.Applet;
import java.awt.Graphics;

public class ShowStatusDemo extends Applet
  public void paint(Graphics g)
    g.drawString("Hello World", 50, 75); // using drawString() to display in applet window
    showStatus("Greetings");             // using showStatus() to display in status bar

Output screen when run SSD.html file.


Leave a Comment

Your email address will not be published.