Androidberry logo Androidberry text logo
AndroidBerry Home
  • Learn Java
  • Java Programs
  • Interview Questions
  • Androidberry facebook
  • Androidberry twitter
  • Androidberry google plus

Java Tutorials


Basic Introduction

Decision Making

Looping

Classes and Objects

Inheritance

Interface

Packages

Exception Handling

Multithreading

Java Multithreading
Creating a Thread
Thread Life Cycle
Thread Exceptions
Thread Synchronization

Java Applets

What is Applet?
Java Applet vs Application
Creating a Applet
Displaying Applet on Webpage
Applet Lifecycle
Applet Tag
Passing Parameters to Applet
Setting Color to applet
Update and Repaint method
Using Fonts in Applet

Graphics Programming

Intro. to Graphics class
Drawing - Lines , Rectangles
Drawing - Circles and Ellipse
Drawing - Arcs
Drawing - Polygons
Drawing - Bar Charts

More on Java

Java Programs
Java Keywords Dictionary
Java Interview Questions

Java Setting Font


Java Font in Applet

A font determines look of the text when it is painted. Font is used when painting text on a Graphics context and is a property of AWT Component.

All Fonts are stored into Font class.

Properties of Font class

  • Family Name - It specifies the general name of the font.
  • Logical Name - It specifies the category of the font.
  • Face Name - It specifies specific font

How to set font?

1. To set the font to applet first of all create an object of Font class.

Syntax

Font fontObj = new Font (String FontName, int FontStyle, int FontSize);

Explanation

  • FontName - It specifies name of the font. Java Supports Dialog, DialogFont,Serif ,Sans Serif, Monospaced and Symbol.
  • FontStyle - It specifies the different font style to font. It has 3 constants as

  • Constant Description
    Font.BOLD It makes the font style bold.
    Font.ITALIC It makes the font style Italic.
    Font.PLAIN It make the font style plain.

    Multiple font style can be applied by using OR | symbol Ex- Font.BOLD|Font.PLAIN

  • FontSize - It specifies the font size in integers.

2. After creating an object java has setFont () method to set the font.

Syntax

void setFont (fontObj);

Example

Font myFont = new Font("Consolas",Font.BOLD,30);
setFont (myFont);

NOTE : Applet has default fontName = 'Dialog', Font size = 12 , font style = 'PLAIN'.

Font Class Methods

Method Name Syntax Description
getFamily String getFamily() This method returns the family name of current font object.
getFont static Font getFont(String nm) This method returns a Font Object from system properties list.
getFontName String getFontName() This method returns the font face name.
getSize int getSize() This method returns the point size of font, rounded to an integer.
getStyle int getStyle() This method returns the style of the font.
isPlain boolean isPlain() This method returns a boolean true if font is plain otherwise returns false.
isItalic boolean isItalic() This method returns a boolean true if font is italic otherwise returns false.
isBol boolean isBol() This method returns a boolean true if font is Bold otherwise returns false.

Applet Font Example

Program to make use of Font class methods.


<< Previous Next >>

See Also

All Java Programs
Java Keywords
Java Interview Questions

AndroidBerry Support

About us
Contact us
Suggest us
Questions?

Follow us

Androidberry FacebookFacebook
Androidberry TwitterTwitter
Androidberry GooglePlusGoogle+
Back to top
Androidberry Name Logo