import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
public class JFrameDemo extends JFrame {
Container ct;
JButton jButton1 = new JButton();
public JFrameDemo(){
jbInit();
}
private void jbInit(){
ct = getContentPane(); //得到面板内容
this.setSize(new Dimension(200, 100)); //设定窗口的宽度为200,高度为200
this.setTitle("Frame Title"); //设定窗口的标题
jButton1.setText("connect"); //设定按钮的标签
Icon ic = new ImageIcon("local.jpg");
jButton1.setIcon(ic);
//jButton1.setBorder(BorderFactory.createLineBorder(Color.red));
ct.add(jButton1, "Center"); //将按钮加入内容面板
this.setVisible(true); //显示窗口
}
public static void main(String[] args) throws ClassNotFoundException,
InstantiationException,
IllegalAccessException,
UnsupportedLookAndFeelException{
//默认风格
System.out.println("default" + UIManager.getLookAndFeel().getName());
LookAndFeelInfo[] lAndF = UIManager.getInstalledLookAndFeels();
//遍历L&F风格种类
for(int j = 0; j < lAndF.length; j++){
System.out.println("feel is " + lAndF[j].getClassName());
}
//设置Windows风格
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
//设置Motif风格
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
//设置Metal风格
//UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
JFrameDemo jf = new JFrameDemo();
jf.addWindowListener(new WindowAdapter(){ //匿名类用于注册监听者
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
}