?? frame1.java
字號:
package ex09_05;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Frame1 extends JFrame { JPanel contentPane; JLabel jLabel1 = new JLabel(); JButton jButton1 = new JButton(); JTextField jTextField1 = new JTextField(); JButton jButton2 = new JButton(); /**Construct the frame*/ public Frame1() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /**Component initialization*/ private void jbInit() throws Exception { //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]"))); contentPane = (JPanel) this.getContentPane(); jLabel1.setText("jLabel1"); jLabel1.setBounds(new Rectangle(14, 16, 141, 29)); contentPane.setLayout(null); this.setSize(new Dimension(400, 300)); this.setTitle("Frame Title"); jButton1.setText("取得資料"); jButton1.setBounds(new Rectangle(186, 11, 86, 29)); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton1_actionPerformed(e); } }); jTextField1.setBounds(new Rectangle(17, 49, 142, 29)); jButton2.setText("設置資料"); jButton2.setBounds(new Rectangle(185, 52, 87, 29)); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton2_actionPerformed(e); } }); contentPane.add(jLabel1, null); contentPane.add(jButton1, null); contentPane.add(jTextField1, null); contentPane.add(jButton2, null); } /**Overridden so we can exit when window is closed*/ protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } void jButton1_actionPerformed(ActionEvent e) {String test;//取得文本框內的資料test=jTextField1.getText();//設置標簽的顯示文本jLabel1.setText(test); } void jButton2_actionPerformed(ActionEvent e) {jTextField1.setText("我是文本框"); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -