Java AWT Example - Font - Internet & Web Programming Lab

Program:

import java.awt.*;
import java.awt.event.*;

class font extends Frame implements ItemListener
{
 Choice c1,c2,c3;
 Label lb;
 int a,b;
 String c;
 font()
 {
   setLayout(null);
   setSize(500,400);
   setVisible(true);
   setTitle("Java Awt : Font");
   c1=new Choice();
   c2=new Choice();
   c3=new Choice();
   lb=new Label(null);
   lb.setBackground(Color.white);
   lb.setForeground(Color.blue);
   lb.setAlignment(1);
   c1.setBounds(50,100,100,20);
   add(c1);
   c2.setBounds(160,100,100,20);
   add(c2);
   c3.setBounds(270,100,100,20);
   add(c3);
   lb.setBounds(10,200,480,60);
   add(lb);
   c1.addItemListener(this);
   c2.addItemListener(this);
   c3.addItemListener(this);
   lb.setText("www.2k8618.blogspot.com");
   c1.add("Normal");
   c1.add("Bold");
   c1.add("Italic");
   for(int i=8;i<72;i+=2)
     c2.add(Integer.toString(i));
     GraphicsEnvironment
     ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
     String f[]=ge.getAvailableFontFamilyNames();
     for(int i=0;i<f.length;i++)
        c3.add(f[i]);

   addWindowListener(new WindowAdapter()
   {
    public void windowClosing(WindowEvent we)
    {
     System.exit(0);
    }
   });
 }

 public void itemStateChanged(ItemEvent ae)
 {
  if(c1==ae.getSource())
  {
        if(c1.getSelectedIndex()==0)
          a=Font.PLAIN;
        else if(c1.getSelectedIndex()==1)
          a=Font.BOLD;
        else if(c1.getSelectedIndex()==2)
          a=Font.ITALIC;
        lb.setFont(new Font(c,a,b));
        lb.setText(lb.getText());
  }
  if(c2==ae.getSource())
  {
    b=Integer.parseInt(c2.getSelectedItem());
    lb.setFont(new Font(c,a,b));
    lb.setText(lb.getText());
  }
  if(c3==ae.getSource())
  {
    c=c3.getSelectedItem();
    lb.setFont(new Font(c,a,b));
    lb.setText(lb.getText());
  }
 }

 public static void main(String s[])
 {
  font ob=new font();
 }
}


Output:

nn@linuxmint ~/Desktop/java_all $ javac font.java
nn@linuxmint ~/Desktop/java_all $ java font
nn@linuxmint ~/Desktop/java_all $



2 comments:

  1. Nice Blog information.
    GIEC Global is the Best Education Consultants in Melbourne, Australia and education consultant in Melbourne, Sydney, Brisbane, Perth, Adelaide,Australia.Education Consultants in Melbourne, Best Education Agent in Melbourne, Sydney, Adelaide, Perth, and Brisbane is GIEC Global. We are Melbourne Migration and Education Consultants, Education Migration Agent Melbourne, Melbourne Study Abroad, and Performance Education Melbourne

    ReplyDelete
  2. Very informative and impressive post you have written, this is quite interesting and I have gone through it completely, an upgraded information is shared, keep sharing such valuable information. Find the best Medical supplies Australia

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...