hellojframe.java
来自「教你如何使用ANT来写JAVA脚本,这里边是ANT教程的示例.」· Java 代码 · 共 77 行
JAVA
77 行
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 + =
减小字号Ctrl + -
显示快捷键?