Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 6

K. K.

Wagh Polytechnic, Nashik-3

Chapter 5

Java Applets and Graphics


Programming
Use of Font Class

• The Font class states fonts, that are used to render text in a visible
way.
• It is used to set or retrieve the screen font.
• The AWT supports multiple types of fonts.
• Fonts have a family name, a logical font name, and a face name.
• The family name is the general name of the font, such as Courier.
• The logical name specifies a category of font, such as Serif.
• The face name specifies a specific font, such as Courier Italic.
• Fonts are encapsulated by the Font class.
Use of Font Class Cont.
• To Create object of Font Class following Constructor is used:
Font(String fontName, int fontStyle, int pointSize)
• Here,
• fontName specifies the name of the desired font.
Dialog is also the default if you don’t explicitly set a font.
• fontStyle specifies style of the font. It may consist of one
or more of these three constants:
• Font.PLAIN, Font.BOLD, and Font.ITALIC.
• To combine styles, | or + Operator is used.
• Ex: Font.BOLD | Font.ITALIC OR
Font. BOLD + Font.ITALIC specifies a bold, italics style.
• pointSize specifies the size, in points, of the font is
Font Class Methods
i) setFont():
To use a font that you have created, you must select it using
setFont( ), which is defined by Component.
It has this general form:
Syntax: void setFont(Font fontObj)
Here, fontObj is the object that contains the desired font.
ii) getFont():
Suppose you want to obtain information about the currently
selected font. To do this, you must first get the current font by
calling getFont( ).
This method is defined by the Graphics class, as shown here:
Syntax: Font getFont( )
Font Class Methods
iii) getAvailableFontFamilyNames(): When working with
fonts sometimes we want to know available font families in the
system.
Syntax: String[] getAvailableFontFamilyNames()
This method returns an arrays of string which contains all
available font family.
iv) getAllFonts(): This method returns the array of font object
for all the available fonts.
Syntax: Font[] getAllFonts()
v) getFamily(): It returns the name of the font family to which
invoking font object belongs.
Syntax: String getFamily()
vi) getFontName(): It returns the face name of invoking font
Syntax: String getFontName()
Font Class Methods Cont.
vii) getName(): Returns the logical name of invoking font.
Syntax: String getName ()
viii) getStyle(): This method returns style values of the invoking
fonts.
Syntax: int getStyle()
ix) getSize(): It returns the size of the invoking font.
Syntax: int getSize()
x) boolean isBold()
xi)boolean isItalic()
xii)boolean isPlain()

You might also like