📄 hellojframe.java
字号:
import java.awt.BorderLayout;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JOptionPane;import javax.swing.UIManager;import javax.swing.UnsupportedLookAndFeelException;import javax.swing.WindowConstants;public class HelloJFrame extends javax.swing.JFrame { private JButton jButton1; /** * Auto-generated main method to display this JFrame */ public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (ClassNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (InstantiationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IllegalAccessException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (UnsupportedLookAndFeelException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } HelloJFrame inst = new HelloJFrame(); inst.setVisible(true); } public HelloJFrame() { super(); initGUI(); } private void initGUI() { try { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); FlowLayout thisLayout = new FlowLayout(); getContentPane().setLayout(thisLayout); this.setTitle("Ant Test Frame"); { jButton1 = new JButton(); getContentPane().add(jButton1); jButton1.setText("Hello"); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jButton1ActionPerformed(evt); } }); } pack(); setSize(400, 300); } catch (Exception e) { e.printStackTrace(); } } private void jButton1ActionPerformed(ActionEvent evt) { System.out.println("jButton1.actionPerformed, event=" + evt); JOptionPane.showMessageDialog(this, "Hello JFrame!"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -