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

Introduction

Content

Apply

Reflect

Extend

previous.gif
 (3087 bytes)

next.gif
 (2959 bytes)

 

Content Index

Content Page # 14

Fonts

The font is the overall appearance and size of text. Java allows all components and controls to select a different font if required. The program can also draw text on, say, a Canvas object in any font. Java does not provide fonts; it only uses fonts provided by the system the Java program is running on.

A Java user interface element that has text on it (e.g., Button, Label, Choice) can display that text in any font. The component's setFont()method is used to select the font that will be used.

When a program uses drawString() to write text on the screen, it is written in the current font, whatever that happens to be. When the font is changed (for a specific Graphics object), this affects all drawing methods on the same graphics object. The method that selects the font in a Graphics object is also called setFont().

The fact that Java does not provide its own fonts means that the programmer has to be rather careful in the choice of fonts if a program has to be truly portable. Even typefaces that look very similar have different names on different platforms. For example, the typeface called ‘helvetica' on Unix systems is very similar to ‘arial' on Windows systems, but you would never guess from the names.

Note: terms like ‘font', ‘typeface', ‘style', ‘italic', etc., have very precise meanings in typography, but they become very vague in the computer graphics field. Sadly, you will see these terms used to mean a range of different things in different textbooks and articles.

Back to top

basicline.gif (169 bytes)

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