Applet Example Draw Strings and Graphics

Applet Example Draw Strings and Graphics



Applet Example Displaying Strings in Status Bar

An applet can display the messages on the applet window (using drawString()) and on status bar (using showStatus()). 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).

Let us see what Java Applet API says about showStatus() method;

  • strong>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.

File Name: DisplayMethods.java

File Name: DisplayMethods.html


Applet Example

Screenshot of Applet Example DisplayMethods.html

g.drawString(“Hello World”, 50, 60);
showStatus(“Best Wishes”);

drawString() method draws the string "Hello World" at x and y coordinates of 50 and 60.

showStatus() method displays the string "Best Wishes" on the status bar. This method does not take x and y coordinates.

3 thoughts on “Applet Example Draw Strings and Graphics

  1. moaz amin

    sir Graphics is an Abstract class then how we create object of Graphics to call methods drawString() it is very confuseable for me

  2. sangeeth reddy

    sir executing the above code gives following error.. 1) “paint (java.awt.Graphics) in Awt cannot override paint(java.awt.Graphics) in java.awt.Container; overriding method is static
    public static void paint(Graphics g)
    ^
    2) non-static variable s1 cannot be referenced from a static context g.drawString(s1, 100, 100);
    ^

    2) non-static variable s1 cannot be referenced from a static context g.drawString(s2, 100, 100);
    ^

Leave a Reply

Your email address will not be published. Required fields are marked *