⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calculator.java~58~

📁 很好得jbuilder100例源代码
💻 JAVA~58~
字号:
package untitled1;import java.awt.*;import java.awt.event.*;import java.applet.*;import com.borland.jbcl.layout.*;/** * Title: * Description: * Copyright:    Copyright (c) 2001 * Company: * @author * @version 1.0 */public class calculator extends Applet {  double startnum;  boolean isResult = false;  boolean flagAdd = false;  boolean flagSub = false;  boolean flagMul = false;  boolean flagDiv = false;  double endnum;  String str = null;  boolean isStandalone = false;  Button button1 = new Button();  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();  Button button10 = new Button();  Button button11 = new Button();  Button button12 = new Button();  Button button13 = new Button();  Button button14 = new Button();  Button button15 = new Button();  TextField text = new TextField();  Button button16 = new Button();  Button button17 = new Button();  GridBagLayout gridBagLayout1 = new GridBagLayout();  /**Get a parameter value*/  public String getParameter(String key, String def) {    return isStandalone ? System.getProperty(key, def) :      (getParameter(key) != null ? getParameter(key) : def);  }  /**Construct the applet*/  public calculator() {  }  /**Initialize the applet*/  public void init() {    try {      jbInit();    }    catch(Exception e) {      e.printStackTrace();    }  }  /**Component initialization*/  private void jbInit() throws Exception {    button1.setFont(new java.awt.Font("Dialog", 0, 8));    button1.setLabel("1");    button1.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button1_actionPerformed(e);      }    });    this.setLayout(gridBagLayout1);    button2.setFont(new java.awt.Font("Dialog", 0, 10));    button2.setLabel("2");    button2.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button1_actionPerformed(e);      }    });    button3.setFont(new java.awt.Font("Dialog", 0, 10));    button3.setLabel("3");    button3.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button1_actionPerformed(e);      }    });    button4.setFont(new java.awt.Font("Dialog", 0, 10));    button4.setLabel("4");    button4.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button1_actionPerformed(e);      }    });    button5.setFont(new java.awt.Font("Dialog", 0, 10));    button5.setLabel("5");    button5.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button1_actionPerformed(e);      }    });    button6.setFont(new java.awt.Font("Dialog", 0, 10));    button6.setLabel("6");    button6.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button1_actionPerformed(e);      }    });    button7.setFont(new java.awt.Font("Dialog", 0, 10));    button7.setLabel("7");    button7.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button1_actionPerformed(e);      }    });    button8.setFont(new java.awt.Font("Dialog", 0, 10));    button8.setLabel("8");    button8.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button1_actionPerformed(e);      }    });    button9.setFont(new java.awt.Font("Dialog", 0, 10));    button9.setLabel("9");    button9.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button1_actionPerformed(e);      }    });    button10.setFont(new java.awt.Font("Dialog", 0, 10));    button10.setLabel("0");    button10.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button1_actionPerformed(e);      }    });    button11.setFont(new java.awt.Font("Dialog", 0, 10));    button11.setLabel(".");    button11.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button11_actionPerformed(e);      }    });    button12.setFont(new java.awt.Font("Dialog", 0, 10));    button12.setLabel("+");    button12.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button12_actionPerformed(e);      }    });    button13.setFont(new java.awt.Font("Dialog", 0, 10));    button13.setLabel("-");    button13.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button13_actionPerformed(e);      }    });    button14.setFont(new java.awt.Font("Dialog", 0, 10));    button14.setLabel("*");    button14.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button14_actionPerformed(e);      }    });    button15.setFont(new java.awt.Font("Dialog", 0, 10));    button15.setLabel("/");    button15.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button15_actionPerformed(e);      }    });    this.setEnabled(true);    this.setFont(new java.awt.Font("Dialog", 0, 10));    button16.setLabel("c");    button16.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button16_actionPerformed(e);      }    });    button17.setLabel("=");    button17.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button17_actionPerformed(e);      }    });    text.setEditable(false);//    text.setEditable(false);    text.setText("0");    this.add(button3,  new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(15, 20, 0, 0), -1, 13));    this.add(button4,  new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(11, 10, 0, 0), -1, 13));    this.add(button5,  new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(11, 20, 0, 0), -1, 13));    this.add(button6,  new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(11, 20, 0, 0), -1, 13));    this.add(button7,  new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 10, 0, 0), -1, 13));    this.add(button8,  new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 20, 0, 0), -1, 13));    this.add(button9,  new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 20, 0, 0), -1, 13));    this.add(button10,  new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 10, 0, 0), -1, 13));    this.add(button11,  new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 20, 0, 0), 3, 13));    this.add(button12,  new GridBagConstraints(3, 4, 1, 1, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 20, 0, 0), -1, 13));    this.add(button13,  new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 10, 9, 0), 3, 13));    this.add(button14,  new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 20, 9, 0), 1, 13));    this.add(button15,  new GridBagConstraints(3, 5, 1, 1, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 20, 9, 0), 3, 13));    this.add(button2,  new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(15, 20, 0, 0), -1, 13));    this.add(text,  new GridBagConstraints(1, 0, 3, 1, 1.0, 0.0            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(8, 10, 0, 0), 149, 5));    this.add(button16,  new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(16, 10, 0, 0), -1, 11));    this.add(button17,  new GridBagConstraints(4, 1, 1, 2, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(15, 20, 30, 112), 7, 32));    this.add(button1,  new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(15, 10, 0, 0), 1, 17));  }  /**Get Applet information*/  public String getAppletInfo() {    return "Applet Information";  }  /**Get parameter info*/  public String[][] getParameterInfo() {    return null;  }  void button1_actionPerformed(ActionEvent e) {      if (isResult){        text.setText("0");        isResult = !isResult;      }      str = text.getText();      if (str.equals("0")){        text.setText(e.getActionCommand());      }      else{        str=str+e.getActionCommand();        text.setText(str);      }  }  void button11_actionPerformed(ActionEvent e) {     if(str.indexOf(".")<1) {       str=str+".";       button12.setLabel(str);       text.setText(str);     }  }  void button16_actionPerformed(ActionEvent e) {      text.setText("0");  }  void button12_actionPerformed(ActionEvent e) {        startnum = Double.parseDouble(text.getText());        flagAdd = true;        isResult = true;  }  void button13_actionPerformed(ActionEvent e) {        startnum = Double.parseDouble(text.getText());        flagSub = true;        isResult = true;  }  void button14_actionPerformed(ActionEvent e) {        startnum = Double.parseDouble(text.getText());        flagMul = true;        isResult = true;  }  void button15_actionPerformed(ActionEvent e) {        startnum = Double.parseDouble(text.getText());        flagDiv = true;        isResult = true;  }  void button17_actionPerformed(ActionEvent e) {        String strchip;        int step;        endnum = Double.parseDouble(text.getText());        if(flagAdd){              text.setText(String.valueOf(startnum+endnum));              isResult = true;              flagAdd = !flagAdd;        }        if(flagSub){          text.setText(String.valueOf(startnum-endnum));          isResult = true;          flagSub = !flagSub;        }        if(flagMul){          text.setText(String.valueOf(startnum*endnum));          isResult = true;          flagMul = !flagMul;        }        if((flagDiv)&&(endnum!=0)){          text.setText(String.valueOf(startnum/endnum));          isResult = true;          flagDiv = !flagDiv;        }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -