您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes

Introduction

Content

Apply

Reflect

Extend

previous.gif
 (3087 bytes)

next.gif
 (2959 bytes)

 

Content Index

Content Page # 5

Example of simple applet using object of graphics class

You will have seen many applets that use objects of the Graphics class. For example, a Graphics object is the argument automatically passed to the applet when the system invokes the paint() method.

Consider the output of this applet:

The applet producing this output is as follows:

import java.applet.Applet;

import java.awt.*;

public class DrawString1 extends Applet
{

  public void paint( Graphics g )
  {
    g.drawString( "text drawn with Graphics method 'drawString()'",
         20, 20 );
  }

 } // class

Here a messagedrawString(...)is passed to the Graphics object g— resulting in the invocation of the drawString()method of the class Graphics.

Back to top

basicline.gif (169 bytes)

RITSEC - Global Campus
Copyright ?1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg