R4R
Right Place For Right Person TM
 

R4R JAVAAWT ExamplesSet font of string in java

previous

Home

Next

Set font of string in java

In this example we are going to set font of the strings.
To set font we can use method:
g.setFont( a ): where a denote the Font type For example:-
a=new Font("Algerian",Font.plain,25) as shown in our example.
To set different font to different you have to defined the the font of each string before each string as shown in our example.



//Set Font
import java.applet.*;
import java.awt.*;
//<applet code="SetFont" width=200 height=200></applet>
public class SetFont extends Applet
{
Font a,b,c;
public void init(){
setBackground(Color.cyan);
a=new Font("Algerian",Font.PLAIN,25);
b=new Font("TimesRoman",Font.BOLD + Font.ITALIC,45);
c=new Font("Courier",Font.ITALIC,30);
}
public void paint(Graphics g){
g.setFont(a);
g.setColor(Color.black);
g.drawString("Set font",10,20);
g.setFont(b);
g.setColor(Color.blue);
g.drawString("Shrish singh",10,60);
g.setFont(c);
g.setColor(Color.yellow);
g.drawString("From Unnao",10,90);
}
}

Download source code

Output of  Example

previous

Home

Next

New Updates

R4R
R4R
R4R
R4R
R4R
R4R
R4R
R4R