|
|  |
Fonts and Graphics
Fonts, Random Numbers and Timers
This applet demonstrates the use of True Type Fonts in Java. Basically you have only the choice between TimesRoman, Courier and Helvetica if you want your applet to run on all machines. Fonts are objects which have to be created with new. You can add the BOLD and ITALIC attributes seperately or in combination. The size can be set in the last parameter of the Font constructor.
|
//Sourcecode
import java.awt.*;
import java.applet.*;
//demonstrates the use of fonts
public class Project6 extends Applet
{
Font font1 = new Font("Helvetica", Font.PLAIN, 22);
Font font2 = new Font("TimesRoman", Font.PLAIN, 20);
Font font3 = new Font("Courier", Font.PLAIN, 18);
Font font4 = new Font("Helvetica", Font.BOLD, 16);
Font font5 = new Font("Helvetica", Font.ITALIC, 16);
Font font6 = new Font("Helvetica", Font.BOLD + Font.ITALIC, 16);
public void paint(Graphics g)
{
g.setFont(font1);
g.drawString("This is Font 1 (Helvetica)", 30,30);
g.setFont(font2);
g.drawString("This is Font 2 (TimesRoman)", 30,80);
g.setFont(font3);
g.drawString("This is Font 3 (Courier)", 30,130);
g.setFont(font4);
g.drawString("This is Helvetica Bold", 30,180);
g.setFont(font5);
g.drawString("This is Helvetica Italic", 30,230);
g.setFont(font6);
g.drawString("This is Helvetica Bold and Italic", 30,280);
}
}
|
|
 |
|