最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java實現(xiàn)計算器模板及源碼

 更新時間:2022年06月06日 17:26:52   作者:原創(chuàng)小白變怪獸  
這篇文章主要為大家詳細介紹了java實現(xiàn)計算器模板及源碼,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

計算器實現(xiàn)了大部分基礎(chǔ)功能:基本運算,菜單欄選項,并且拓展了普通型和科學(xué)興選項等等,讀者可以在此基礎(chǔ)上進行修改和拓展。其他具體實現(xiàn)方法可以看源碼,里面有詳細的概述,代碼框架清晰。

運行環(huán)境:win10 Eclipse IDE for Java Developers - 2020-06

下面是計算器的視圖:

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

/*
?* 計算器
?*/
public class CaculatorTest implements ActionListener {
?? ?// 初始框架搭建
?? ?JFrame frame = new JFrame("計算器");
?? ?JTextField area = new JTextField("0");
?? ?JPanel panel1 = new JPanel();
?? ?JPanel panel2 = new JPanel();
?? ?JButton[] buttons = new JButton[20];
?? ?String[] buttonsText = { "sqrt", "退格", "C", "/", "7", "8", "9", "*", "4", "5", "6", "-", "1", "2", "3", "+", "0",
?? ??? ??? ?".", "+/-", "=" };
?? ?boolean point = false; // 用于判斷是否輸入多位小數(shù)點
?? ?boolean key = true; // 做完運算("=")后繼續(xù)輸入數(shù)字
?? ?String sign = " "; // 用于判斷和記錄運算符號
?? ?double temp = 0; // 多次連續(xù)運算時,值的寄存處

?? ?public CaculatorTest() {
?? ??? ?initMenu();
?? ??? ?initText();
?? ??? ?initExtend();
?? ??? ?initFrame();
?? ??? ?initBorderLayout();
?? ?}

?? ?// 初始化菜單
?? ?private void initMenu() {
?? ??? ?JMenuBar mb = new JMenuBar();
?? ??? ?JMenu m1 = new JMenu("選項");
?? ??? ?JMenu m2 = new JMenu("編輯");
?? ??? ?JMenu m3 = new JMenu("幫助");
?? ??? ?JMenuItem m11 = new JMenuItem("普通型計算器");
?? ??? ?JMenuItem m12 = new JMenuItem("科學(xué)型計算器");
?? ??? ?m1.add(m11);
?? ??? ?m1.add(m12);
?? ??? ?m11.addActionListener(new ActionListener() {
?? ??? ??? ?@Override
?? ??? ??? ?public void actionPerformed(ActionEvent e) {
?? ??? ??? ??? ?boolean flag = false;
?? ??? ??? ??? ?panel2.setVisible(flag);
?? ??? ??? ??? ?frame.pack();
?? ??? ??? ?}
?? ??? ?});
?? ??? ?m12.addActionListener(new ActionListener() {
?? ??? ??? ?@Override
?? ??? ??? ?public void actionPerformed(ActionEvent e) {
?? ??? ??? ??? ?boolean flag = true;
?? ??? ??? ??? ?panel2.setVisible(flag);
?? ??? ??? ??? ?frame.pack();
?? ??? ??? ?}
?? ??? ?});
?? ??? ?mb.add(m1);
?? ??? ?mb.add(m2);
?? ??? ?mb.add(m3);
?? ??? ?frame.setJMenuBar(mb);
?? ?}

?? ?// 初始化輸出文本域
?? ?private void initText() {
?? ??? ?area.setFont(new Font("TimesRoman", Font.PLAIN, 20));
?? ??? ?area.setSize(400, 100);
?? ??? ?area.setHorizontalAlignment(JTextField.RIGHT); // 向右顯示
?? ?}

?? ?// 初始化拓展功能
?? ?private void initExtend() {
?? ??? ?panel2.setLayout(new GridLayout(1,4,1,1));
?? ??? ?JButton b1 = new JButton("sin");
?? ??? ?JButton b2 = new JButton("cos");
?? ??? ?JButton b3 = new JButton("exp");
?? ??? ?JButton b4 = new JButton("ln");
?? ??? ?b1.setFont(new Font("TimesRoman", Font.PLAIN, 20));
?? ??? ?b2.setFont(new Font("TimesRoman", Font.PLAIN, 20));
?? ??? ?b3.setFont(new Font("TimesRoman", Font.PLAIN, 20));
?? ??? ?b4.setFont(new Font("TimesRoman", Font.PLAIN, 20));
?? ??? ?b1.setSize(100, 100);
?? ??? ?b1.addActionListener(this);
?? ??? ?b2.setSize(100, 100);
?? ??? ?b2.addActionListener(this);
?? ??? ?b3.setSize(100, 100);
?? ??? ?b3.addActionListener(this);
?? ??? ?b4.setSize(100, 100);
?? ??? ?b4.addActionListener(this);
?? ??? ?panel2.add(b1);
?? ??? ?panel2.add(b2);
?? ??? ?panel2.add(b3);
?? ??? ?panel2.add(b4);
?? ?}

?? ?// 初始化計算器基本界面
?? ?private void initFrame() {
?? ??? ?panel1.setLayout(new GridLayout(5, 4, 1, 1));
?? ??? ?for (int i = 0; i < buttonsText.length; i++) {
?? ??? ??? ?JButton button = new JButton(buttonsText[i]);
?? ??? ??? ?button.setSize(100, 100);
?? ??? ??? ?button.setFont(new Font("TimesRoman", Font.PLAIN, 20));
?? ??? ??? ?button.addActionListener(this);
?? ??? ??? ?panel1.add(button);
?? ??? ?}
?? ?}

?? ?// 初始化計算器總基本界面
?? ?private void initBorderLayout() {
?? ??? ?frame.setLayout(new BorderLayout());
?? ??? ?frame.add(panel1, BorderLayout.SOUTH); // 插入組件
?? ??? ?frame.add(area, BorderLayout.NORTH);
?? ??? ?frame.add(panel2, BorderLayout.CENTER);
?? ??? ?frame.setLocation(700, 400);
?? ??? ?frame.setSize(400, 700);
?? ??? ?frame.setVisible(true); // 設(shè)置可見
?? ??? ?panel2.setVisible(false);
?? ??? ?frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 可以關(guān)閉
?? ??? ?frame.pack();
?? ?}

?? ?public static void main(String[] args) {
?? ??? ?new CaculatorTest();
?? ?}

?? ?@Override
?? ?// 事件監(jiān)聽
?? ?public void actionPerformed(ActionEvent e) {
?? ??? ?String str = e.getActionCommand();
?? ??? ?String str2 = area.getText();
?? ??? ?if (str == "0" || str == "1" || str == "2" || str == "3" || str == "4" || str == "5" || str == "6" || str == "7"
?? ??? ??? ??? ?|| str == "8" || str == "9") {
?? ??? ??? ?if (key == false) {
?? ??? ??? ??? ?area.setText(str2 + str);
?? ??? ??? ?} else {
?? ??? ??? ??? ?area.setText(str);
?? ??? ??? ??? ?key = false;
?? ??? ??? ?}
?? ??? ?} else if (str == "C") {
?? ??? ??? ?area.setText("0");
?? ??? ??? ?sign = " ";
?? ??? ??? ?key = true;
?? ??? ?} else if (str == ".") {
?? ??? ??? ?if (point == false) {
?? ??? ??? ??? ?area.setText(str2 + str);
?? ??? ??? ??? ?point = true;
?? ??? ??? ?} else {
?? ??? ??? ??? ?area.setText("double poits!press C to update!");
?? ??? ??? ??? ?point = false;
?? ??? ??? ?}
?? ??? ?} else if (str == "+/-") {
?? ??? ??? ?double num = Double.valueOf(str2);
?? ??? ??? ?num = -num;
?? ??? ??? ?area.setText(String.valueOf(num));
?? ??? ?} else if (str == "退格") {
?? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ?area.setText("can't be deleted!please press C!");
?? ??? ??? ?} else {
?? ??? ??? ??? ?str2 = str2.substring(0, str2.length() - 1);
?? ??? ??? ??? ?area.setText(str2);
?? ??? ??? ?}
?? ??? ?} else if (str == "sqrt") {
?? ??? ??? ?area.setText("");
?? ??? ??? ?sign = "s";
?? ??? ?} else if (str == "sin") {
?? ??? ??? ?area.setText("");
?? ??? ??? ?sign = "sin";
?? ??? ?} else if (str == "cos") {
?? ??? ??? ?area.setText("");
?? ??? ??? ?sign = "cos";
?? ??? ?} else if (str == "exp") {
?? ??? ??? ?area.setText("");
?? ??? ??? ?sign = "exp";
?? ??? ?} else if (str == "ln") {
?? ??? ??? ?area.setText("");
?? ??? ??? ?sign = "ln";
?? ??? ?} else {
?? ??? ??? ?if (str == "+") {
?? ??? ??? ??? ?if (sign == " ") {
?? ??? ??? ??? ??? ?sign = "+";
?? ??? ??? ??? ??? ?temp = Double.valueOf(str2);
?? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ?} else if (sign == "-") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "+";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = temp - Double.valueOf(str2);
?? ??? ??? ??? ??? ??? ?sign = "+";
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?key = true;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "+") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "+";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = temp + Double.valueOf(str2);
?? ??? ??? ??? ??? ??? ?sign = "+";
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?key = true;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "*") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "+";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = temp * Double.valueOf(str2);
?? ??? ??? ??? ??? ??? ?sign = "+";
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?key = true;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "/") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "+";
?? ??? ??? ??? ??? ?} else if (Double.valueOf(str2) == 0) {
?? ??? ??? ??? ??? ??? ?area.setText("除數(shù)不能為0哦!按 C");
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = temp / Double.valueOf(str2);
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "+";
?? ??? ??? ??? ??? ??? ?key = true;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "s") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "+";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = Math.sqrt(Double.valueOf(str2));
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "+";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "sin") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "+";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = Math.sin(Double.valueOf(str2));
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "+";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "cos") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "+";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = Math.cos(Double.valueOf(str2));
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "+";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "exp") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "+";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = Math.exp(Double.valueOf(str2));
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "+";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "ln") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "+";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = Math.log(Double.valueOf(str2));
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "+";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?}
?? ??? ??? ?} else if (str == "-") {
?? ??? ??? ??? ?if (sign == " ") {
?? ??? ??? ??? ??? ?sign = "-";
?? ??? ??? ??? ??? ?temp = Double.valueOf(str2);
?? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ?} else if (sign == "-") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "-";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = temp - Double.valueOf(str2);
?? ??? ??? ??? ??? ??? ?sign = "-";
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?key = true;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "+") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "-";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = temp + Double.valueOf(str2);
?? ??? ??? ??? ??? ??? ?sign = "-";
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?key = true;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "*") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "-";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = temp * Double.valueOf(str2);
?? ??? ??? ??? ??? ??? ?sign = "-";
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?key = true;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "/") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "-";
?? ??? ??? ??? ??? ?} else if (Double.valueOf(str2) == 0) {
?? ??? ??? ??? ??? ??? ?area.setText("除數(shù)不能為0哦!按 C");
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = temp / Double.valueOf(str2);
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "-";
?? ??? ??? ??? ??? ??? ?key = true;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "s") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "-";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = Math.sqrt(Double.valueOf(str2));
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "-";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "sin") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "-";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = Math.sin(Double.valueOf(str2));
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "-";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "cos") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "-";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = Math.cos(Double.valueOf(str2));
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "-";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "exp") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "-";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = Math.exp(Double.valueOf(str2));
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "-";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "ln") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "-";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = Math.log(Double.valueOf(str2));
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "-";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?}
?? ??? ??? ?} else if (str == "*") {
?? ??? ??? ??? ?if (sign == " ") {
?? ??? ??? ??? ??? ?sign = "*";
?? ??? ??? ??? ??? ?temp = Double.valueOf(str2);
?? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ?} else if (sign == "-") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "*";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = temp - Double.valueOf(str2);
?? ??? ??? ??? ??? ??? ?sign = "*";
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?key = true;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "+") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "*";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = temp + Double.valueOf(str2);
?? ??? ??? ??? ??? ??? ?sign = "*";
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?key = true;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "*") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "*";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = temp * Double.valueOf(str2);
?? ??? ??? ??? ??? ??? ?sign = "*";
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?key = true;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "/") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "*";
?? ??? ??? ??? ??? ?} else if (Double.valueOf(str2) == 0) {
?? ??? ??? ??? ??? ??? ?area.setText("除數(shù)不能為0哦!按 C");
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = temp / Double.valueOf(str2);
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "*";
?? ??? ??? ??? ??? ??? ?key = true;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "s") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "*";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = Math.sqrt(Double.valueOf(str2));
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "*";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "sin") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "*";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = Math.sin(Double.valueOf(str2));
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "*";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "cos") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "*";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = Math.cos(Double.valueOf(str2));
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "*";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "exp") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "*";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = Math.exp(Double.valueOf(str2));
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "*";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "ln") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "*";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = Math.log(Double.valueOf(str2));
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "*";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?}
?? ??? ??? ?} else if (str == "/") {
?? ??? ??? ??? ?if (sign == " ") {
?? ??? ??? ??? ??? ?sign = "/";
?? ??? ??? ??? ??? ?temp = Double.valueOf(str2);
?? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ?} else if (sign == "-") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "/";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = temp - Double.valueOf(str2);
?? ??? ??? ??? ??? ??? ?sign = "/";
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?key = true;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "+") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "/";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = temp + Double.valueOf(str2);
?? ??? ??? ??? ??? ??? ?sign = "/";
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?key = true;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "*") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "/";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = temp * Double.valueOf(str2);
?? ??? ??? ??? ??? ??? ?sign = "/";
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?key = true;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "/") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "/";
?? ??? ??? ??? ??? ?} else if (Double.valueOf(str2) == 0) {
?? ??? ??? ??? ??? ??? ?area.setText("除數(shù)不能為0哦!按 C");
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = temp / Double.valueOf(str2);
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "/";
?? ??? ??? ??? ??? ??? ?key = true;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "s") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "/";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = Math.sqrt(Double.valueOf(str2));
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "/";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "sin") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "/";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = Math.sin(Double.valueOf(str2));
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "/";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "cos") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "/";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = Math.cos(Double.valueOf(str2));
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "/";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "exp") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "/";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = Math.exp(Double.valueOf(str2));
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "/";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "ln") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?sign = "/";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = Math.log(Double.valueOf(str2));
?? ??? ??? ??? ??? ??? ?area.setText("");
?? ??? ??? ??? ??? ??? ?sign = "/";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?}
?? ??? ??? ?} else if (str == "=") {
?? ??? ??? ??? ?if (sign == "+") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?area.setText(String.valueOf(temp));
?? ??? ??? ??? ??? ??? ?sign = " ";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = temp + Double.valueOf(str2);
?? ??? ??? ??? ??? ??? ?area.setText(String.valueOf(temp));
?? ??? ??? ??? ??? ??? ?sign = " ";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "-") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?area.setText(String.valueOf(temp));
?? ??? ??? ??? ??? ??? ?sign = " ";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = temp - Double.valueOf(str2);
?? ??? ??? ??? ??? ??? ?area.setText(String.valueOf(temp));
?? ??? ??? ??? ??? ??? ?sign = " ";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "*") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?area.setText(String.valueOf(temp));
?? ??? ??? ??? ??? ??? ?sign = " ";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = temp * Double.valueOf(str2);
?? ??? ??? ??? ??? ??? ?area.setText(String.valueOf(temp));
?? ??? ??? ??? ??? ??? ?sign = " ";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "/") {
?? ??? ??? ??? ??? ?if (Double.valueOf(str2) == 0) {
?? ??? ??? ??? ??? ??? ?area.setText("除數(shù)不能為0哦!按C");
?? ??? ??? ??? ??? ??? ?sign = " ";
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = temp / Double.valueOf(str2);
?? ??? ??? ??? ??? ??? ?area.setText(String.valueOf(temp));
?? ??? ??? ??? ??? ??? ?sign = " ";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == " ") {
?? ??? ??? ??? ??? ?if (str2.length() == 0) {
?? ??? ??? ??? ??? ??? ?area.setText(String.valueOf(temp));
?? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ?temp = Double.valueOf(str2);
?? ??? ??? ??? ??? ??? ?area.setText(String.valueOf(temp));
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} else if (sign == "s") {
?? ??? ??? ??? ??? ?temp = Math.sqrt(Double.valueOf(str2));
?? ??? ??? ??? ??? ?area.setText(String.valueOf(temp));
?? ??? ??? ??? ??? ?sign = " ";
?? ??? ??? ??? ?} else if (sign == "sin") {
?? ??? ??? ??? ??? ?temp = Math.sin(Double.valueOf(str2));
?? ??? ??? ??? ??? ?area.setText(String.valueOf(temp));
?? ??? ??? ??? ??? ?sign = " ";
?? ??? ??? ??? ?} else if (sign == "cos") {
?? ??? ??? ??? ??? ?temp = Math.cos(Double.valueOf(str2));
?? ??? ??? ??? ??? ?area.setText(String.valueOf(temp));
?? ??? ??? ??? ??? ?sign = " ";
?? ??? ??? ??? ?} else if (sign == "exp") {
?? ??? ??? ??? ??? ?temp = Math.exp(Double.valueOf(str2));
?? ??? ??? ??? ??? ?area.setText(String.valueOf(temp));
?? ??? ??? ??? ??? ?sign = " ";
?? ??? ??? ??? ?} else if (sign == "ln") {
?? ??? ??? ??? ??? ?temp = Math.log(Double.valueOf(str2));
?? ??? ??? ??? ??? ?area.setText(String.valueOf(temp));
?? ??? ??? ??? ??? ?sign = " ";
?? ??? ??? ??? ?}
?? ??? ??? ??? ?key = true;
?? ??? ??? ?}
?? ??? ?}
?? ?}
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 基于Springboot+Mybatis對數(shù)據(jù)訪問層進行單元測試的方式分享

    基于Springboot+Mybatis對數(shù)據(jù)訪問層進行單元測試的方式分享

    本文將介紹一種快高效、可復(fù)用的解決測試方案——對數(shù)據(jù)訪問層做單元測試,文章通過代碼示例介紹的非常詳細,具有一定的參考價值,需要的朋友可以參考下
    2023-07-07
  • Java中Easypoi實現(xiàn)excel多sheet表導(dǎo)入導(dǎo)出功能

    Java中Easypoi實現(xiàn)excel多sheet表導(dǎo)入導(dǎo)出功能

    這篇文章主要介紹了Java中Easypoi實現(xiàn)excel多sheet表導(dǎo)入導(dǎo)出功能,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習或者工作具有一定的參考學(xué)習價值,需要的朋友們下面隨著小編來一起學(xué)習學(xué)習吧
    2021-01-01
  • 在eclipse中使用SVN的實現(xiàn)方法(圖文教程)

    在eclipse中使用SVN的實現(xiàn)方法(圖文教程)

    這篇文章主要介紹了在eclipse中使用SVN的實現(xiàn)方法(圖文教程),文中通過圖文介紹的非常詳細,對大家的學(xué)習或者工作具有一定的參考學(xué)習價值,需要的朋友們下面隨著小編來一起學(xué)習學(xué)習吧
    2020-07-07
  • 關(guān)于Spring3 + Mybatis3整合時多數(shù)據(jù)源動態(tài)切換的問題

    關(guān)于Spring3 + Mybatis3整合時多數(shù)據(jù)源動態(tài)切換的問題

    這篇文章主要介紹了關(guān)于Spring3 + Mybatis3整合時多數(shù)據(jù)源動態(tài)切換的問題,需要的朋友可以參考下
    2017-04-04
  • Spring?MVC如何實現(xiàn)接口Controller定義控制器

    Spring?MVC如何實現(xiàn)接口Controller定義控制器

    這篇文章主要介紹了Spring?MVC如何實現(xiàn)接口Controller定義控制器,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-02-02
  • 淺談java Collection中的排序問題

    淺談java Collection中的排序問題

    下面小編就為大家?guī)硪黄獪\談java Collection中的排序問題。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-12-12
  • 使用Lombok時@JsonIgnore注解失效解決方案

    使用Lombok時@JsonIgnore注解失效解決方案

    這篇文章主要為大家介紹了使用Lombok時@JsonIgnore注解失效問題解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-06-06
  • JUC之CountdownLatch使用詳解

    JUC之CountdownLatch使用詳解

    這篇文章主要介紹了JUC之CountdownLatch使用詳解,CountdownLatch 用來進行線程同步協(xié)作,等待所有線程完成倒計時,
    其中構(gòu)造參數(shù)用來初始化等待計數(shù)值,await() 用來等待計數(shù)歸零,countDown() 用來讓計數(shù)減一,需要的朋友可以參考下
    2023-12-12
  • 帶你快速入門掌握Spring的那些注解使用

    帶你快速入門掌握Spring的那些注解使用

    注解是個好東西,注解是Java語法,被Java編譯器檢查,可以減少配置錯誤,這篇文章主要給大家介紹了關(guān)于Spring的那些注解使用的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-02-02
  • Spring中IoC優(yōu)點與缺點解析

    Spring中IoC優(yōu)點與缺點解析

    這篇文章主要為大家詳細解析了Spring中IoC優(yōu)點與缺點,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-11-11

最新評論

田林县| 同德县| 周口市| 朝阳市| 荔波县| 体育| 临洮县| 罗田县| 循化| 泸西县| 钦州市| 松江区| 西藏| 马关县| 安国市| 响水县| 安福县| 奉新县| 庐江县| 淄博市| 漳州市| 吉林省| 平陆县| 望江县| 巧家县| 古田县| 滨州市| 嘉鱼县| 文昌市| 商都县| 黄大仙区| 盈江县| 余干县| 龙井市| 沽源县| 泸溪县| 武安市| 祁连县| 光泽县| 厦门市| 三亚市|