Showing posts with label java font-online help. Show all posts
Showing posts with label java font-online help. Show all posts

Wednesday, 3 July 2019

Java Font class - Online Help

Java Fonts class:

Java provides Font class contained in the java.awt package. The class font is used to set the fonts used in the graphical object. This class contains constructors and methods for manipulating fonts in the applet program. The font class is the part of Java Abstract Windowing Toolkit (AWT). The Font class states fonts, which are used to render text in a visible way.

Constructors available in java font class:

The font class defines the following constructors:

-Font()

     Creates a new Font from the specified

-Font(String font_name,int font_style,int font_size)

     The font class constructor has three arguments: Font name, font style, font size. The size of a font is measured as points. A point is 1/72 of an inch. The following table shows the font style constants used in the font class.

Font.PLAIN - Represent a plain font style
Font.BOLD  - Represent a bold font style
Font.ITALIC- Represent an italic font style

Methods available in java font class:

The commonly used method is as follows:

String getName()
Returns the name of the current font.

int getStyle()
Return the current style of the font.

int getSize()
Returns the size of the current font.

String getFamily()
Returns the name of the family of the font.

boolean isBold()
Indicates whether or not this Font object's style is BOLD.



boolean isItalic()
Indicates whether or not this Font object's style is ITALIC.

boolean isPlain()
Indicates whether or not this Font object's style is PLAIN.

String toString()
Converts this Font object to a String representation.

float getSize2D()
Returns the point size of this Font in float value.

static Font getFont(String nm)
Returns a Font object from the system properties list.

static Font getFont(String nm, Font font)
Gets the specified Font from the system properties list



Sample program for java font class:

import java.awt.*;
import java.applet.*;
/*
<applet code="font" width=250 height=200>
</applet>
*/
public class fontd extends Applet
{
public void paint(Graphics g)
{
Font f= new Font("arial",Font.ITALIC,40);
g.setFont(f);
g.drawString("online help"25,35);
}
}