Professional Documents
Culture Documents
XAVIER’S COLLEGE
MAITIGHAR, KATHMANDU
Lab Report 1
Text and Fonts
Submitted by
Jeshika Baniya
019BIM017
Submitted to
Mr. Ganesh Yogi
Lecturer
Department of Computer Science
St. Xavier’s College
Theory:
In Java, Font is a class that belongs to java. awt package. It implements the Serializable interface.
FontUIResource is the direct known subclass of the Java Font class.
An instance of the Font class represents a specific font to the system. Within AWT, a font is
specified by its name, style, and point size. Each platform that This method returns a String array
of the fonts available. Under Java 1.0, on any platform, the available fonts were: TimesRoman,
Helvetica, Courier, Dialog, DialogInput, and ZapfDingbats. For copyright reasons, the list is
substantially different in Java 1.1: the available font names are TimesRoman images, Serif,
Helvetica images, SansSerif, Courier images, Monospaced, Dialog, and DialogInput. The actual
fonts available aren't changing; the deprecated font names are being replaced by non-copyrighted
equivalents. Thus, TimesRoman is now Serif, Helvetica is now SansSerif, and Courier is
Monospaced.
1
protected Font() ()
Creates a new Font from the specified font.
2
Font(Map<? extends AttributedCharacterIterator.Attribute,?> attributes)
Creates a new Font from the specified font.
3
Font(String name, int style, int size)
Creates a new Font from the specified font.
Algorithm
Step 1:
Import libraries
import java.awt.*
import javax.swing.*
import java.awt.Font
Step 2:
Using the constructor to create a font class and set font.
Font f1= new Font("Helvetica", Font.ITALIC, 22);
setFont(f1);
Step 3:
Write a string and print in an applet window or AWT/Swing window.
drawString("The required text", Font.ITALIC, 22);
Program
package jeshika;
import java.awt.*;
import java.swing.*;
import javax.swing.*;
public class fontexample extends JFrame
{
fontexample()
{
setSize(500,700);
setLayout(new FlowLayout(FlowLayout.CENTER));
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
Conclusion
After completing this lab report, I have known how to set specific text with different font colors
and different styles.