?? frame1.java~13~
字號:
package calculator1;import java.awt.*;import java.awt.event.*;import javax.swing.*;import com.borland.jbcl.layout.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2008</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class Frame1 extends JFrame { JPanel contentPane; Button button1 = new Button(); XYLayout xYLayout1 = new XYLayout(); Button button2 = new Button(); Button button3 = new Button(); Button button4 = new Button(); Button button5 = new Button(); Button button6 = new Button(); Button button7 = new Button(); Button button8 = new Button(); Button button9 = new Button(); TextField textField1 = new TextField(); //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(); button1.setFont(new java.awt.Font("Dialog", 1, 15)); button1.setLabel("1"); button1.addActionListener(new Frame1_button1_actionAdapter(this)); contentPane.setLayout(xYLayout1); this.setSize(new Dimension(259, 414)); this.setTitle("Frame Title"); button2.setFont(new java.awt.Font("Dialog", 1, 15)); button2.setLabel("2"); button2.addActionListener(new Frame1_button2_actionAdapter(this)); button3.setFont(new java.awt.Font("Dialog", 1, 15)); button3.setLabel("3"); button3.addActionListener(new Frame1_button3_actionAdapter(this)); button4.setFont(new java.awt.Font("Dialog", 1, 15)); button4.setLabel("4"); button4.addActionListener(new Frame1_button4_actionAdapter(this)); button5.setFont(new java.awt.Font("Dialog", 1, 15)); button5.setLabel("5"); button5.addActionListener(new Frame1_button5_actionAdapter(this)); button6.setFont(new java.awt.Font("Dialog", 1, 15)); button6.setLabel("6"); button6.addActionListener(new Frame1_button6_actionAdapter(this)); button7.setFont(new java.awt.Font("Dialog", 1, 15)); button7.setLabel("7"); button7.addActionListener(new Frame1_button7_actionAdapter(this)); button8.setFont(new java.awt.Font("Dialog", 1, 15)); button8.setLabel("8"); button8.addActionListener(new Frame1_button8_actionAdapter(this)); button9.setFont(new java.awt.Font("Dialog", 1, 15)); button9.setLabel("9"); button9.addActionListener(new Frame1_button9_actionAdapter(this)); textField1.setFont(new java.awt.Font("Dialog", 1, 20)); textField1.setText(""); button10.setFont(new java.awt.Font("Dialog", 1, 15)); button10.setLabel("0"); button10.addActionListener(new Frame1_button10_actionAdapter(this)); button11.setFont(new java.awt.Font("Dialog", 1, 15)); button11.setLabel("."); button11.addActionListener(new Frame1_button11_actionAdapter(this)); button12.setBackground(Color.green); button12.setFont(new java.awt.Font("Dialog", 1, 15)); button12.setLabel("+"); button12.addActionListener(new Frame1_button12_actionAdapter(this)); button13.setBackground(Color.green); button13.setFont(new java.awt.Font("Dialog", 1, 15)); button13.setForeground(Color.black); button13.setLabel("="); button13.addActionListener(new Frame1_button13_actionAdapter(this)); button14.setBackground(Color.green); button14.setFont(new java.awt.Font("Dialog", 1, 15)); button14.setLabel("-"); button14.addActionListener(new Frame1_button14_actionAdapter(this)); button15.setBackground(Color.green); button15.setFont(new java.awt.Font("Dialog", 1, 15)); button15.setLabel("*"); button15.addActionListener(new Frame1_button15_actionAdapter(this)); button16.setBackground(Color.green); button16.setFont(new java.awt.Font("Dialog", 1, 15)); button16.setLabel("/"); button16.addActionListener(new Frame1_button16_actionAdapter(this)); button17.setBackground(Color.pink); button17.setFont(new java.awt.Font("Dialog", 1, 13)); button17.setLabel("C"); button17.addActionListener(new Frame1_button17_actionAdapter(this)); contentPane.setBackground(SystemColor.textInactiveText); contentPane.add(button1, new XYConstraints(9, 257, 45, 45)); contentPane.add(button2, new XYConstraints(66, 257, 45, 45)); contentPane.add(button3, new XYConstraints(125, 257, 45, 45)); contentPane.add(button4, new XYConstraints(9, 201, 45, 45)); contentPane.add(button5, new XYConstraints(66, 201, 45, 45)); contentPane.add(button6, new XYConstraints(125, 201, 45, 45)); contentPane.add(button9, new XYConstraints(125, 144, 45, 45)); contentPane.add(button8, new XYConstraints(66, 144, 45, 45)); contentPane.add(button7, new XYConstraints(9, 144, 45, 45)); contentPane.add(button11, new XYConstraints(125, 314, 45, 45)); contentPane.add(button12, new XYConstraints(183, 143, -1, 102)); contentPane.add(button13, new XYConstraints(183, 257, -1, 101)); contentPane.add(textField1, new XYConstraints(9, 29, 214, 37)); contentPane.add(button17, new XYConstraints(9, 84, 45, 45)); contentPane.add(button14, new XYConstraints(183, 84, 45, 45)); contentPane.add(button15, new XYConstraints(125, 84, 45, 45)); contentPane.add(button16, new XYConstraints(66, 84, 45, 45)); contentPane.add(button10, new XYConstraints(9, 314, 98, 45)); } //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); } } ////////////////////////////////////////////////////////// double m=0,n=0,z=0; int fuhao=0; String w=""; String test; Button button10 = new Button(); Button button11 = new Button(); Button button12 = new Button(); Button button13 = new Button(); Button button14 = new Button(); Button button15 = new Button(); Button button16 = new Button(); Button button17 = new Button(); void button1_actionPerformed(ActionEvent e) { test="1"; www(); this.textField1.setText(w); } void www() { w=w.concat(test); return; } void button2_actionPerformed(ActionEvent e) { test="2"; www(); this.textField1.setText(w); } void button3_actionPerformed(ActionEvent e) { test="3"; www(); this.textField1.setText(w); } void button4_actionPerformed(ActionEvent e) { test="4"; www(); this.textField1.setText(w); } void button5_actionPerformed(ActionEvent e) { test="5"; www(); this.textField1.setText(w); } void button6_actionPerformed(ActionEvent e) { test="6"; www(); this.textField1.setText(w); } void button7_actionPerformed(ActionEvent e) { test="7"; www(); this.textField1.setText(w); } void button8_actionPerformed(ActionEvent e) { test="8"; www(); this.textField1.setText(w); } void button9_actionPerformed(ActionEvent e) { test="9"; www(); this.textField1.setText(w); } void button10_actionPerformed(ActionEvent e) { test="0"; www(); this.textField1.setText(w); } void button11_actionPerformed(ActionEvent e) { test="."; www(); this.textField1.setText(w); } void button13_actionPerformed(ActionEvent e) { if(w!=""){ n=Double.parseDouble(w); switch (fuhao) { case 1: z = m + n; break; case 2: z = m - n; break; case 3: z = m * n; break; case 4: z = m / n; break; case 0: this.textField1.setText("ERROR"); break; } m = z; w = Double.toString(z); this.textField1.setText(w); w = ""; } else this.textField1.setText("ERROR"); } void button12_actionPerformed(ActionEvent e) { if(m==0) { if (w == "") w="0"; m = Double.parseDouble(w); } fuhao=1; this.textField1.setText(""); w=""; } void button14_actionPerformed(ActionEvent e) { if(m==0) { if (w == "") w="0"; m = Double.parseDouble(w); } fuhao=2; this.textField1.setText(""); w=""; } void button15_actionPerformed(ActionEvent e) { if(m==0) { if (w == "") w="0"; m = Double.parseDouble(w); } fuhao=3; this.textField1.setText(""); w=""; } void button16_actionPerformed(ActionEvent e) { if(m==0) { if (w == "") w="0"; m = Double.parseDouble(w); } fuhao=4; this.textField1.setText(""); w=""; } void button17_actionPerformed(ActionEvent e) { m=0;n=0;z=0; fuhao=0; w=""; test=""; this.textField1.setText(""); }}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); }}class Frame1_button2_actionAdapter implements java.awt.event.ActionListener { Frame1 adaptee; Frame1_button2_actionAdapter(Frame1 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.button2_actionPerformed(e); }}class Frame1_button3_actionAdapter implements java.awt.event.ActionListener { Frame1 adaptee; Frame1_button3_actionAdapter(Frame1 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.button3_actionPerformed(e); }}class Frame1_button4_actionAdapter implements java.awt.event.ActionListener { Frame1 adaptee; Frame1_button4_actionAdapter(Frame1 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.button4_actionPerformed(e); }}class Frame1_button5_actionAdapter implements java.awt.event.ActionListener { Frame1 adaptee; Frame1_button5_actionAdapter(Frame1 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.button5_actionPerformed(e); }}class Frame1_button6_actionAdapter implements java.awt.event.ActionListener { Frame1 adaptee; Frame1_button6_actionAdapter(Frame1 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.button6_actionPerformed(e); }}class Frame1_button7_actionAdapter implements java.awt.event.ActionListener { Frame1 adaptee; Frame1_button7_actionAdapter(Frame1 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.button7_actionPerformed(e); }}class Frame1_button8_actionAdapter implements java.awt.event.ActionListener { Frame1 adaptee; Frame1_button8_actionAdapter(Frame1 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.button8_actionPerformed(e); }}class Frame1_button9_actionAdapter implements java.awt.event.ActionListener { Frame1 adaptee; Frame1_button9_actionAdapter(Frame1 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.button9_actionPerformed(e); }}class Frame1_button10_actionAdapter implements java.awt.event.ActionListener { Frame1 adaptee; Frame1_button10_actionAdapter(Frame1 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.button10_actionPerformed(e); }}class Frame1_button11_actionAdapter implements java.awt.event.ActionListener { Frame1 adaptee; Frame1_button11_actionAdapter(Frame1 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.button11_actionPerformed(e); }}class Frame1_button13_actionAdapter implements java.awt.event.ActionListener { Frame1 adaptee; Frame1_button13_actionAdapter(Frame1 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.button13_actionPerformed(e); }}class Frame1_button12_actionAdapter implements java.awt.event.ActionListener { Frame1 adaptee; Frame1_button12_actionAdapter(Frame1 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.button12_actionPerformed(e); }}class Frame1_button14_actionAdapter implements java.awt.event.ActionListener { Frame1 adaptee; Frame1_button14_actionAdapter(Frame1 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.button14_actionPerformed(e); }}class Frame1_button15_actionAdapter implements java.awt.event.ActionListener { Frame1 adaptee; Frame1_button15_actionAdapter(Frame1 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.button15_actionPerformed(e); }}class Frame1_button16_actionAdapter implements java.awt.event.ActionListener { Frame1 adaptee; Frame1_button16_actionAdapter(Frame1 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.button16_actionPerformed(e); }}class Frame1_button17_actionAdapter implements java.awt.event.ActionListener { Frame1 adaptee; Frame1_button17_actionAdapter(Frame1 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.button17_actionPerformed(e); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -