?? frame1.java~15~
字號:
package javabook.lecture2.myexprtest;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Frame1 extends JFrame {
JPanel contentPane;
JLabel statusBar = new JLabel();
FlowLayout flowLayout1 = new FlowLayout();
Label label1 = new Label();
TextField textField1 = new TextField();
TextField textField2 = new TextField();
Button button1 = new Button();
TextArea textArea1 = new TextArea();
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(flowLayout1);
this.setSize(new Dimension(400, 250));
this.setTitle("我的計算器");
statusBar.setText(" ");
label1.setText("請輸入兩個整型數據");
textField1.setColumns(7);
textField1.setText("");
textField2.setColumns(7);
textField2.setText("");
button1.setLabel("確認");
button1.addActionListener(new Frame1_button1_actionAdapter(this));
textArea1.setColumns(50);
textArea1.setEditable(false);
textArea1.setEnabled(true);
textArea1.setText("");
textArea1.setVisible(true);
contentPane.setToolTipText("");
contentPane.setVerifyInputWhenFocusTarget(true);
contentPane.add(statusBar, null);
contentPane.add(label1, null);
contentPane.add(textField1, null);
contentPane.add(textField2, null);
contentPane.add(button1, null);
contentPane.add(textArea1, 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 button1_actionPerformed(ActionEvent e) {
try{
int a = Integer.parseInt(textField1.getText());
int b = Integer.parseInt(textField2.getText());
textArea1.setText("");
textArea1.append(a + " + " + b + " = " + (a + b) + "\n");
textArea1.append(a + " - " + b + " = " + (a - b) + "\n");
textArea1.append(a + " * " + b + " = " + (a * b) + "\n");
textArea1.append(a + " / " + b + " = " + (a / b) + "\n");
textArea1.append(a + " % " + b + " = " + (a % b) + "\n");
}catch(Exception e){
textArea1.append(e.getMessage());
}
}
}
class Frame1_button1_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_button1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.button1_actionPerformed(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -