?? frame1.java
字號:
package sayhello;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Frame1 extends JFrame { JPanel contentPane; FlowLayout flowLayout1 = new FlowLayout(); Label label1 = new Label(); TextField textField1 = new TextField(); Label label2 = new Label(); TextField textField2 = new TextField(); Button button1 = new Button(); Button button2 = new Button(); Choice choice1 = new Choice(); Label label3 = new Label(); /**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(); label1.setText("姓名:"); contentPane.setLayout(flowLayout1); this.setResizable(false); this.setSize(new Dimension(359, 110)); this.setTitle("Say Hello"); textField1.setColumns(8); label2.setText("性別:"); textField2.setColumns(12); textField2.setEditable(false); button1.setLabel("確定"); button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); button2.setLabel("清除"); button2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button2_actionPerformed(e); } }); flowLayout1.setHgap(15); flowLayout1.setVgap(10); choice1.setComponentOrientation(null); label3.setText("問候語:"); contentPane.add(label1, null); contentPane.add(textField1, null); contentPane.add(label2, null); contentPane.add(choice1, null); contentPane.add(label3, null); contentPane.add(textField2, null); contentPane.add(button1, null); contentPane.add(button2, null); choice1.add("--男--"); choice1.add("--女--"); } /**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 button1_actionPerformed(ActionEvent e) { String s = new String(); s = textField1.getText(); if (choice1.getSelectedIndex() == 0) s = s + "先生,"; else s = s + "女士,"; s = s + "你好!"; textField2.setText(s); } void button2_actionPerformed(ActionEvent e) { textField1.setText(""); textField2.setText(""); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -