⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 actioneventexample_1.java

📁 该辕马主要针对应用时间作出反映
💻 JAVA
字号:
import javax.swing.*;
import java.awt.event.*;
public class ActionEventExample_1{
  public static void main(String []args){
    new ActionFrame().show();
  }
}
class ActionFrame extends JFrame{
  private JButton btnLookAndFeel=new JButton("Windows");
  public ActionFrame(){
    ActionListener al=new LookAndFeelListener();
    btnLookAndFeel.addActionListener(al);
    JPanel p=new JPanel();
    p.add(btnLookAndFeel);		
    getContentPane().add(p);
    this.setSize(300,200);		
  }
  class LookAndFeelListener implements ActionListener{
    public void actionPerformed(ActionEvent e){
      String text=btnLookAndFeel.getText().trim();
      String lnfName="javax.swing.plaf.metal.MetalLookAndFeel";
      if(text.equals("Windows")){
	lnfName="com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
	btnLookAndFeel.setText("Metal");
      }else if(text.equals("Metal")){
	lnfName="javax.swing.plaf.metal.MetalLookAndFeel";
	btnLookAndFeel.setText("Windows");
      }			
      try{
	UIManager.setLookAndFeel(lnfName); //设定观感
	//更新容器内的所有组件的观感
	SwingUtilities.updateComponentTreeUI(ActionFrame.this); 
      }catch(Exception excp){
	excp.printStackTrace();
      }
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -