📄 jframecaculator.java
字号:
/*
* JFrameCaculator.java
*
* Created on 2007年4月29日, 下午1:26
*/
package gui;
import javax.xml.stream.events.StartDocument;
import java.util.Calendar;
import javax.swing.*;
import java.io.*;
/**
*
* @author Administrator
*/
public class JFrameCaculator extends javax.swing.JFrame {
private String firOper = "";
private String secOper = "";
private String op;
private String firSign = "+";
private String secSign = "-";
private String memNum = "";
private boolean operandType = true;
private boolean firOperContinue = false;
/** Creates new form JFrameCaculator */
public JFrameCaculator() {
initComponents();
this.jTextFieldMem.setText("M");
}
public double getResult(String operator,double firstOperand,double secOperand){
if(operator.equals("+"))
return firstOperand+secOperand;
else if(operator.equals("-"))
return firstOperand-secOperand;
else if(operator.equals("*"))
return firstOperand*secOperand;
else if(operator.equals("/"))
return firstOperand/secOperand;
else return 0;
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">//GEN-BEGIN:initComponents
private void initComponents() {
jButton23 = new javax.swing.JButton();
jSplitPaneGlobal = new javax.swing.JSplitPane();
jPanelTop = new javax.swing.JPanel();
jTextFieldMem = new javax.swing.JTextField();
jTextFieldShow = new javax.swing.JTextField();
jPanelBottom = new javax.swing.JPanel();
jButtonSin = new javax.swing.JButton();
jButtonMC = new javax.swing.JButton();
jButton0 = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButtonAdd = new javax.swing.JButton();
jButtonCls = new javax.swing.JButton();
jButtonCos = new javax.swing.JButton();
jButtonMR = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButtonDec = new javax.swing.JButton();
jButtonTime = new javax.swing.JButton();
jButtonTan = new javax.swing.JButton();
jButtonMS = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton();
jButton8 = new javax.swing.JButton();
jButtonMul = new javax.swing.JButton();
jButtonSqrt = new javax.swing.JButton();
jButtonSign = new javax.swing.JButton();
jButtonM = new javax.swing.JButton();
jButton9 = new javax.swing.JButton();
jButtonPoint = new javax.swing.JButton();
jButtonResult = new javax.swing.JButton();
jButtonDiv = new javax.swing.JButton();
jButtonBackSpace = new javax.swing.JButton();
jButton23.setText("jButton23");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Caculator");
setResizable(false);
jSplitPaneGlobal.setDividerLocation(80);
jSplitPaneGlobal.setDividerSize(10);
jSplitPaneGlobal.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
jPanelTop.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jTextFieldMem.setEditable(false);
jTextFieldMem.setFont(new java.awt.Font("宋体", 0, 18));
jTextFieldMem.setToolTipText("Show the No. stored");
jTextFieldMem.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
jTextFieldShow.setFont(new java.awt.Font("宋体", 0, 18));
jTextFieldShow.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
javax.swing.GroupLayout jPanelTopLayout = new javax.swing.GroupLayout(jPanelTop);
jPanelTop.setLayout(jPanelTopLayout);
jPanelTopLayout.setHorizontalGroup(
jPanelTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanelTopLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jTextFieldMem, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(51, 51, 51)
.addComponent(jTextFieldShow, javax.swing.GroupLayout.DEFAULT_SIZE, 343, Short.MAX_VALUE)
.addContainerGap())
);
jPanelTopLayout.setVerticalGroup(
jPanelTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelTopLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanelTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextFieldShow, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextFieldMem, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(20, 20, 20))
);
jSplitPaneGlobal.setTopComponent(jPanelTop);
jPanelBottom.setLayout(new java.awt.GridLayout(4, 6, 10, 10));
jPanelBottom.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jButtonSin.setFont(new java.awt.Font("宋体", 1, 16));
jButtonSin.setText("sin");
jButtonSin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonSinActionPerformed(evt);
}
});
jPanelBottom.add(jButtonSin);
jButtonMC.setFont(new java.awt.Font("宋体", 1, 16));
jButtonMC.setForeground(new java.awt.Color(153, 0, 153));
jButtonMC.setText("MC");
jButtonMC.setToolTipText("Delete the No stored");
jButtonMC.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonMCActionPerformed(evt);
}
});
jPanelBottom.add(jButtonMC);
jButton0.setFont(new java.awt.Font("宋体", 1, 16));
jButton0.setForeground(new java.awt.Color(51, 51, 255));
jButton0.setText("0");
jButton0.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton0ActionPerformed(evt);
}
});
jPanelBottom.add(jButton0);
jButton1.setFont(new java.awt.Font("宋体", 1, 16));
jButton1.setForeground(new java.awt.Color(51, 51, 255));
jButton1.setText("1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanelBottom.add(jButton1);
jButton2.setFont(new java.awt.Font("宋体", 1, 16));
jButton2.setForeground(new java.awt.Color(51, 51, 255));
jButton2.setText("2");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jPanelBottom.add(jButton2);
jButtonAdd.setFont(new java.awt.Font("宋体", 1, 16));
jButtonAdd.setText("+");
jButtonAdd.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonAddActionPerformed(evt);
}
});
jPanelBottom.add(jButtonAdd);
jButtonCls.setFont(new java.awt.Font("宋体", 1, 12));
jButtonCls.setForeground(new java.awt.Color(255, 0, 0));
jButtonCls.setText("CLS");
jButtonCls.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonClsActionPerformed(evt);
}
});
jPanelBottom.add(jButtonCls);
jButtonCos.setFont(new java.awt.Font("宋体", 1, 16));
jButtonCos.setText("cos");
jButtonCos.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonCosActionPerformed(evt);
}
});
jPanelBottom.add(jButtonCos);
jButtonMR.setFont(new java.awt.Font("宋体", 1, 16));
jButtonMR.setForeground(new java.awt.Color(102, 0, 102));
jButtonMR.setText("MR");
jButtonMR.setToolTipText("show the No again");
jButtonMR.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonMRActionPerformed(evt);
}
});
jPanelBottom.add(jButtonMR);
jButton3.setFont(new java.awt.Font("宋体", 1, 16));
jButton3.setForeground(new java.awt.Color(51, 51, 255));
jButton3.setText("3");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jPanelBottom.add(jButton3);
jButton4.setFont(new java.awt.Font("宋体", 1, 16));
jButton4.setForeground(new java.awt.Color(51, 51, 255));
jButton4.setText("4");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
jPanelBottom.add(jButton4);
jButton5.setFont(new java.awt.Font("宋体", 1, 16));
jButton5.setForeground(new java.awt.Color(51, 51, 255));
jButton5.setText("5");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
jPanelBottom.add(jButton5);
jButtonDec.setFont(new java.awt.Font("宋体", 1, 16));
jButtonDec.setText("-");
jButtonDec.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonDecActionPerformed(evt);
}
});
jPanelBottom.add(jButtonDec);
jButtonTime.setFont(new java.awt.Font("宋体", 1, 12));
jButtonTime.setForeground(new java.awt.Color(102, 102, 0));
jButtonTime.setText("TIME");
jButtonTime.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonTimeActionPerformed(evt);
}
});
jPanelBottom.add(jButtonTime);
jButtonTan.setFont(new java.awt.Font("宋体", 1, 16));
jButtonTan.setText("tan");
jButtonTan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonTanActionPerformed(evt);
}
});
jPanelBottom.add(jButtonTan);
jButtonMS.setFont(new java.awt.Font("宋体", 1, 16));
jButtonMS.setForeground(new java.awt.Color(102, 0, 102));
jButtonMS.setText("MS");
jButtonMS.setToolTipText("Store a new No");
jButtonMS.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonMSActionPerformed(evt);
}
});
jPanelBottom.add(jButtonMS);
jButton6.setFont(new java.awt.Font("宋体", 1, 16));
jButton6.setForeground(new java.awt.Color(51, 51, 255));
jButton6.setText("6");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});
jPanelBottom.add(jButton6);
jButton7.setFont(new java.awt.Font("宋体", 1, 16));
jButton7.setForeground(new java.awt.Color(51, 51, 255));
jButton7.setText("7");
jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton7ActionPerformed(evt);
}
});
jPanelBottom.add(jButton7);
jButton8.setFont(new java.awt.Font("宋体", 1, 16));
jButton8.setForeground(new java.awt.Color(51, 51, 255));
jButton8.setText("8");
jButton8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton8ActionPerformed(evt);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -