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

Introduction

Content

Apply

Reflect

Extend

previous.gif
 (3087 bytes)

next.gif
 (2959 bytes)

 

Content Index

Content Page # 18

Example of applet displaying text in different fonts

Consider the applet window below:

The code for this applet is as follows:

import java.applet.Applet;

import java.awt.*;

public class Font1 extends Applet
{

  public void paint( Graphics g )
  {
    Font f1 = new Font ("arial", Font.BOLD, 12);
    Font f2 = new Font ("courier", Font.ITALIC, 14);
    Font f3 = new Font ("courier", Font.PLAIN, 14);
    g.setFont( f1 );
    g.drawString ("Account name:", 10, 20);
    g.drawString ("Account balance: ?quot;, 10, 40);
    g.setFont( f2 );
    g.drawString ("Sir Alfred Robertson", 140, 20);
    g.setFont( f3 );
    g.setColor( Color.red );
    g.drawString ("-5,002.88", 140, 40);
   }
 } // class

Back to top

basicline.gif (169 bytes)

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