Thursday 29 January 2015

Filled Under:

How to change Font of text in applet

For changing font of text in apple applet  you must follow just three steps
To select a new font,you must construct a font object that describes that font.
Font(String fontname,int fontStyle,int pointSize)
There are three font style Font.PLAIN,Font.BOND and Font.ITALIC
Once we we have created we must select it using setFont(),its constructor is shown below
void setFont(Font fontObj)

HTML CODING : 

<html>
<body>
<applet code="fontapp" width="300" height="300">
</applet>
</body>
</html>

CODING :

import java.applet.*;
import java.awt.*;
public class fontapp extends Applet{

public void paint(Graphics g){

Color c2 = new Color(0,139,69);
g.drawString("Pro Java Tricks(without font style)",200,130);
Font f= new Font("forte",Font.ITALIC,36);
g.setFont(f);
g.setColor(c2);
g.drawString("Pro Java Tricks",200,200);
}

}

OUTPUT:


0 comments:

Post a Comment