java font example

Font in java JFrame Example

package blogger;
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class FontExample extends JFrame {
 JLabel l1;
    JLabel l2;
    JLabel l3;
    Container c=this.getContentPane();
   
 FontExample()
 {
   setBounds(0,0,500,300);
    //====================================================================
        Font f1 = new Font("Courier", Font.PLAIN, 18);
        Font f2 = new Font("Dialog", Font.BOLD, 30);
        Font f3 = new Font("TimesRoman", Font.ITALIC+Font.BOLD, 12);
        
        l1=new JLabel("\"Courier\", Font.PLAIN, 18");
        l1.setFont(f1);
        l2=new JLabel("\"Dialog\", Font.BOLD, 30");
        l2.setFont(f2);
        l3=new JLabel("\"TimesRoman\", Font.ITALIC+Font.BOLD, 12");
        l3.setFont(f3);
      //==================================================================
        
               l1.setBounds(20,20,400,30);
               l2.setBounds(20,80,400,30);
               l3.setBounds(20,140,400,30);
               
        c.add(l1);c.add(l2);c.add(l3);
        c.setLayout(null);
        setVisible(true);
 } 
 public static void main(String arg[])
 {
  new FontExample();
 }
}

OUTPUT

Comments

Popular posts from this blog

File handling in java