用JAVA获取系统字体属性!!!



import  java.awt. * ;
import  java.applet. * ;
import  javax.swing. * ;
import  java.awt.event. * ;
public   class  A2  extends  JApplet
{
String s
="";
GraphicsEnvironment e 
= GraphicsEnvironment.getLocalGraphicsEnvironment();
String[] f 
= e.getAvailableFontFamilyNames();
JComboBox box 
= new JComboBox(f);
JTextField txt 
= new JTextField(20);


public void init()
{
  
this.getContentPane().setLayout(new FlowLayout());
  
this.add(box);
  box.addItemListener(
new myEvent());
  
this.add(txt);
  
this.setBackground(Color.pink);
  txt.setFont(
new Font(box.getItemAt(0).toString(),Font.BOLD,box.getFont().getSize()));
  txt.setText(box.getItemAt(
0).toString());
}

class myEvent implements ItemListener
{  
  
public void itemStateChanged(ItemEvent e)
  
{
   
if(e.getStateChange()==ItemEvent.SELECTED)
   
{
    txt.setFont(
new Font(box.getSelectedItem().toString(),Font.BOLD,box.getFont().getSize()));
    s
=box.getSelectedItem().toString();
    txt.setText(s);
    
   }

   
  }

}


}


下面是html文件:

< HTML >
< HEAD >
HEAD >
< BODY BGCOLOR = " 000000 " >
< CENTER >
< APPLET
code 
=   " A2.class "
width 
=   " 800 "
height 
=   " 550 "  
>
APPLET >
CENTER >
BODY >
HTML >
 

 

你可能感兴趣的:(J2EE,开发)