Ndryshimi i llojit te shkrimit

Ndryshimi i llojit te shkrimit te nje JLabel

Java permban nje klase Font per ndryshimin e llojit te shkrimit .


java.lang.Object
   |_java.awt.Font

• Klasa Font
– Krijon nje objekt qe mban tipin e shkrimit, stilin dhe madhesine (ne point).

• Metoda setFont()
– Kerkon si argument nje objekt te Font

Konstruktoret e klases Font:


Font(Font font)

Krijon nje font te ri me fontin deshiruar.

Font(String name, int style, int size)

krijon nje font te ri me emrin e deshiruar, stilin dhe madhesine.

emri – string qe tregon llojin e shkrimit
stili - Font.PLAIN, Font.BOLD, ose Font.ITALIC.
madhesia – numer qe perfaqeson madhesine ne point te shkrimit. 1 point = 1/72 inch


     import javax.swing.*;
import java.awt.*;
public class JFrame5font
{
public static void main(String[] args)
{
final int GJATESIA = 550;
final int GJERESIA = 150;
Font f1 = new Font("Kitchener SF Bold", Font.BOLD, 30);
Font f2 = new Font("Elephant", Font.BOLD, 35);
JFrame fr = new JFrame("Fonts");
fr.setBounds(100,100,GJATESIA, GJERESIA);
fr.setVisible(true);
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

fr.setLayout(new FlowLayout());

JLabel l1 = new JLabel("Kitchener SF Bold");
JLabel l2 = new JLabel("Elephant",JLabel.LEFT);
l1.setFont(f1);
l2.setFont(f2);

fr.add(l1);
fr.add(l2);
}
}