📄 actioneventexample_1.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 + -