Tutorials : Java by Example : Section 3 :
Section Three Contents
Fonts, Random Numbers and Timers
Flicker Free Graphics, GIF and JPEG Display
Animation with GIF Pictures, Sprite Animation

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);
        }
}

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.