更换JAVA程序的界面风格

简介: /*这个程序主要更换JAVA的界面风格的 * 后两个Mac,CTK风格要在相关的操作系统上才能实现 */import java.awt.*;import javax.swing.*;import java.
+关注继续查看

/*这个程序主要更换JAVA的界面风格的
 * 后两个Mac,CTK风格要在相关的操作系统上才能实现
 */
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class JFrameButton extends JFrame implements ActionListener
{
    JButton windLook = new JButton("Windows 窗口");
    JButton unixLook = new JButton("Unix 窗口");
    JButton javaLook = new JButton("Java 窗口");
    JButton macLook = new JButton("Mac 窗口");
    JButton gtkLook = new JButton("GTK 窗口");
    JLabel label = new JLabel("选择界面的风格");
 public JFrameButton()
 {
  this.setLayout(new FlowLayout());
  this.add(label);
  this.add(windLook);
  windLook.addActionListener(this);
  this.add(unixLook);
  unixLook.addActionListener(this);
  this.add(javaLook);
  javaLook.addActionListener(this);
  this.add(macLook);
  macLook.addActionListener(this);
  this.add(gtkLook);
  gtkLook.addActionListener(this);
 

}


 public void actionPerformed(ActionEvent e)
 {
  String look = "javax.swing.plaf.metal.MetalLookAndFeel";
  if(e.getSource()==javaLook)
   look = "javax.swing.plaf.metal.MetalLookAndFeel";
  else if(e.getSource()==windLook)
   look = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
  else if(e.getSource()==unixLook)
   look = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
  else if(e.getSource()==macLook)
   look = "com.sun.java.swing.plaf.mac.MacLookAndFeel";
  else if(e.getSource()==gtkLook)
   look = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";

   try
  {
   UIManager.setLookAndFeel(look);
   SwingUtilities.updateComponentTreeUI(this);
  }
  catch(Exception ex)
  {
   System.out.println("Exception:"+ex); 
  }
 }
 public static void main(String[] args)
 {
  JFrameButton jwb = new JFrameButton();
  jwb.setTitle("界面风格设置");
  jwb.setLocationRelativeTo(null);//窗口居中显示
  jwb.setResizable(false);
  jwb.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  jwb.setSize(600,100);
  jwb.setVisible(true);
 }
}

程序运行的效果:

目录
相关文章
|
7天前
|
Java 数据库 数据安全/隐私保护
【java】个人项目:中小学数学卷子自动生成程序
【java】个人项目:中小学数学卷子自动生成程序
|
7天前
|
Java Linux Windows
在Windows操作系统上运行Java程序
在Windows操作系统上运行Java程序
27 2
|
7天前
|
Java API 开发工具
Java程序如何通过阿里云OpenAPI调用短信接口
Java程序如何通过阿里云OpenAPI调用短信接口
25 1
|
13天前
|
Java 数据安全/隐私保护
阿里云平台上进行Java程序的编译与运行
练习对Java程序的编译与运行
23 1
|
13天前
|
弹性计算 Java 数据安全/隐私保护
使用Java面向对象编写网络通信程序应用
本实验将提供一台 Windows Server 2012 64位的 ECS 实例。首先进行Java环境的搭建与配置,然后进行Python开发环境的搭建与配置,最后使用Java与Python语言分别编写与运行简单程序,并进行验证。
15 0
|
21天前
|
网络协议 Java
Java通信程序TCP
Java通信程序TCP
13 0
|
21天前
|
网络协议 Java
Java通信程序UDP
Java通信程序UDP
15 0
|
21天前
|
NoSQL Java Unix
使用JDB调试Java程序
如何使用JDB命令行调试Java程序呢?
22 0
相关产品
云迁移中心
推荐文章
更多