分享
 
 
 

记事本写的科学计算器(源代码)

王朝java/jsp·作者佚名  2006-01-27
窄屏简体版  字體: |||超大  

/**

* Calculator

* A shareware calculator

*

* @author {@link http://blog.csdn.net/hongweijin Bingbing Li}

*

* @recitation 0101 Matt Carlson

*

* @date 12/7/2005 12:08AM

*

*/

import javax.swing.*;

import javax.swing.border.*;

import java.awt.*;

import java.awt.event.*;

public class Calculator extends JFrame implements ActionListener

{

public static final int WIDTH = 800; // width of the window

public static final int HEIGHT = 600; // height of the window

public static final int BUTTON_WIDTH = 80; // width of the buttons

public static final int BUTTON_HEIGHT = 60; // height of the buttons

private CardLayout dealer; // card layout

private JPanel deckPanel; // used to card layout

private JTextField result; // the calculate result

private JCheckBoxMenuItem scientificMode; // the menu item of the mode

private Box vPanel1; // the first line buttons of the

// scientific mode.

private JButton mod; // the modular button

private JButton xey; // the button of Yth root of X

private JButton ms; // save button

private JButton mr; // release the stored value

private JButton mc; // clear the stored value

private double head = 0.0; // the first number of the equation

private double tail = 0.0; // the second number of the equation

private boolean substitution = true; // whether substituted the answer or not

private String operatedCommand = "NOTHING"; // the current operated command

private String preOperatedCommand = "NOTHING"; // remember the pre-operated command

private double variableMemory = 0.0; // the variable of the memory

private JButton jButtonR; // the register's button

private JButton jButtonE; // the edit's button

private JTextField nameField; // the field of the name

private JTextField countryField; // the field of the country

private JTextField zipField; // the field of the zip

private JTextField stateField; // the field of the state

private JTextField cityField ; // the field of the city

private JTextField streetAddressField; // the field of the address

private JTextField first; // the first part of the key

private JTextField second; // the second part of the key

private JTextField third; // the third part of the key

private JTextField fourth; // the fourth part of the key

public Calculator()

{

setSize(WIDTH, HEIGHT);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setTitle("Normal Calculator");

Container contentPre = getContentPane(); // the container of the window

dealer = new CardLayout(); // create a new card layout

deckPanel = new JPanel();

deckPanel.setLayout(dealer);

Box content = Box.createVerticalBox(); // create a new vertical Box

Box registration = Box.createVerticalBox();

/****************************************************

* menu

* file

*****************************************************/

JMenu fileMenu = new JMenu("File");

JMenuItem exitItemOfFile = new JMenuItem("Exit");

exitItemOfFile.addActionListener(this);

fileMenu.add(exitItemOfFile);

/**

* menu

* settings

*/

JMenu settingsMenu = new JMenu("Settings");

JMenuItem registrationInfo = new JMenuItem("Registration Info");

registrationInfo.addActionListener(this);

settingsMenu.add(registrationInfo);

scientificMode = new JCheckBoxMenuItem("Scientific Mode");

scientificMode.addActionListener(this);

settingsMenu.add(scientificMode);

JMenuBar jMenuBar = new JMenuBar();

jMenuBar.add(fileMenu);

jMenuBar.add(settingsMenu);

setJMenuBar(jMenuBar);

/****************************************************

* textFiled panel

*****************************************************/

result = new JTextField("0"); // the initiated value of the answer

result.setBackground(Color.CYAN); // set the back ground color with cyan

result.setHorizontalAlignment(JTextField.RIGHT); // set the horizontal alignment

content.add(result);

content.add(paintButtons());

deckPanel.add("cal", content); // add the calculators card to the layout

registration.add(paintRegistration()); // add the register window

deckPanel.add("reg", registration); // add the register window to the layout

contentPre.add(deckPanel); // add the cards to the container

}

/**

* paint the buttons of the two models.

*

*/

public Box paintButtons()

{

/****************************************************

* Buttons

*****************************************************/

/**

* line1

*/

vPanel1 = Box.createVerticalBox();

// add the backwards's button

JButton backwards = new JButton("1/X");

backwards.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

backwards.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

backwards.addActionListener(this);

vPanel1.add(backwards);

// add the factorial button

JButton factorial = new JButton("X!");

factorial.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

factorial.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

factorial.addActionListener(this);

vPanel1.add(factorial);

// add the square's button

JButton square = new JButton("<html>X<sup>2</sup></html>");

square.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

square.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

square.addActionListener(this);

square.setActionCommand("sqr");

vPanel1.add(square);

// add the square root's button

JButton squareRoot = new JButton("\u221a");

squareRoot.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

squareRoot.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

squareRoot.addActionListener(this);

vPanel1.add(squareRoot);

// add the power's button

JButton power = new JButton("<html>X<sup>Y</sup></html>");

power.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

power.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

power.addActionListener(this);

power.setActionCommand("pow");

vPanel1.add(power);

/**

* line2

*/

Box vPanel2 = Box.createVerticalBox();

// add the modular button

mod = new JButton("Mod");

mod.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

mod.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

mod.addActionListener(this);

vPanel2.add(mod);

// add the seven button

JButton seven = new JButton("7");

seven.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

seven.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

seven.addActionListener(this);

vPanel2.add(seven);

// add the four button

JButton four = new JButton("4");

four.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

four.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

four.addActionListener(this);

vPanel2.add(four);

// add the one button

JButton one = new JButton("1");

one.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

one.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

one.addActionListener(this);

vPanel2.add(one);

// add the zero button

JButton zero = new JButton("0");

zero.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

zero.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

zero.addActionListener(this);

vPanel2.add(zero);

/**

* line3

*/

Box vPanel3 = Box.createVerticalBox();

// add the Yth root of X button

xey = new JButton("XeY");

xey.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

xey.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

xey.addActionListener(this);

vPanel3.add(xey);

// add the eight button

JButton eight = new JButton("8");

eight.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

eight.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

eight.addActionListener(this);

vPanel3.add(eight);

// add the five button

JButton five = new JButton("5");

five.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

five.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

five.addActionListener(this);

vPanel3.add(five);

// add the two button

JButton two = new JButton("2");

two.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

two.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

two.addActionListener(this);

vPanel3.add(two);

// add the dot button

JButton dot = new JButton(".");

dot.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

dot.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

dot.addActionListener(this);

vPanel3.add(dot);

/**

* line4

*/

Box vPanel4 = Box.createVerticalBox();

// add the MS button

ms = new JButton("MS");

ms.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

ms.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

ms.addActionListener(this);

vPanel4.add(ms);

// add the nine button

JButton nine = new JButton("9");

nine.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

nine.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

nine.addActionListener(this);

vPanel4.add(nine);

// add the six button

JButton six = new JButton("6");

six.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

six.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

six.addActionListener(this);

vPanel4.add(six);

// add the three button

JButton three = new JButton("3");

three.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

three.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

three.addActionListener(this);

vPanel4.add(three);

// add the plusMinus button

JButton plusMinus = new JButton("\u00b1");

plusMinus.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

plusMinus.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

plusMinus.addActionListener(this);

vPanel4.add(plusMinus);

/**

* line5

*/

Box vPanel5 = Box.createVerticalBox();

// add the MR button

mr = new JButton("MR");

mr.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

mr.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

mr.addActionListener(this);

vPanel5.add(mr);

// add the division button

JButton division = new JButton("\u00F7");

division.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

division.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

division.addActionListener(this);

vPanel5.add(division);

// add the multiplication button

JButton multiplication = new JButton("\u00d7");

multiplication.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

multiplication.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

multiplication.addActionListener(this);

vPanel5.add(multiplication);

// add the subtract button

JButton subtract = new JButton("-");

subtract.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

subtract.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

subtract.addActionListener(this);

vPanel5.add(subtract);

// add the plus button

JButton plus = new JButton("+");

plus.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

plus.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

plus.addActionListener(this);

vPanel5.add(plus);

/**

* line6

*/

Box vPanel6 = Box.createVerticalBox();

// add the MC button

mc = new JButton("MC");

mc.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

mc.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

mc.addActionListener(this);

vPanel6.add(mc);

// add the C button

JButton c = new JButton("C");

c.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

c.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));

c.addActionListener(this);

vPanel6.add(c);

// add a vertical strut

Component verticalStrut =

Box.createVerticalStrut(BUTTON_HEIGHT);

vPanel6.add(verticalStrut);

// add the enter button

JButton enter = new JButton("=");

enter.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT * 2));

enter.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT * 2));

enter.addActionListener(this);

vPanel6.add(enter);

/**

* Buttons panel

*/

Box buttonsPanel = Box.createHorizontalBox();

buttonsPanel.add(vPanel1);

buttonsPanel.add(vPanel2);

buttonsPanel.add(vPanel3);

buttonsPanel.add(vPanel4);

buttonsPanel.add(vPanel5);

buttonsPanel.add(vPanel6);

/**********************************************************

* the initial state is normal calculator

***********************************************************/

vPanel1.setVisible(false);

mod.setVisible(false);

xey.setVisible(false);

ms.setVisible(false);

mr.setVisible(false);

mc.setVisible(false);

return buttonsPanel;

}

/**

* paint the registration window.

*

*/

public Box paintRegistration()

{

Box registration = Box.createVerticalBox();

/*

* title

*/

JLabel titleRegistration = new JLabel("Bingbing's Calculator Registration");

registration.add(titleRegistration);

/*

* information

*/

JPanel information = new JPanel();

information.setLayout(new GridLayout(6, 2));

//Name

JLabel name = new JLabel("Name:");

nameField = new JTextField();

information.add(name);

information.add(nameField);

//Street Address

JLabel streetAddress = new JLabel("Street Address:");

streetAddressField = new JTextField();

information.add(streetAddress);

information.add(streetAddressField);

//City

JLabel city = new JLabel("City:");

cityField = new JTextField();

information.add(city);

information.add(cityField);

//State

JLabel state = new JLabel("State:");

stateField = new JTextField();

information.add(state);

information.add(stateField);

//Zip

JLabel zip = new JLabel("Zip:");

zipField = new JTextField();

information.add(zip);

information.add(zipField);

//Country

JLabel country = new JLabel("Country:");

countryField = new JTextField();

information.add(country);

information.add(countryField);

registration.add(information);

/*

* Registration Code

*/

Box registrationCode = Box.createVerticalBox();

JPanel registrationCodePanel = new JPanel();

registrationCodePanel.setLayout(new FlowLayout());

//registrationCodePanel.setTitle("Registration Code");

registrationCodePanel.setBorder(new LineBorder(Color.red, 1));

registrationCode.add(registrationCodePanel);

first = new JTextField(3);

registrationCodePanel.add(first);

JLabel rail1 = new JLabel(" - ");

registrationCodePanel.add(rail1);

second = new JTextField(3);

registrationCodePanel.add(second);

JLabel rail2 = new JLabel(" - ");

registrationCodePanel.add(rail2);

third = new JTextField(3);

JLabel rail3 = new JLabel(" - ");

registrationCodePanel.add(third);

registrationCodePanel.add(rail3);

fourth = new JTextField(3);

registrationCodePanel.add(fourth);

/*

* buttons

*/

JPanel buttonsReg = new JPanel();

buttonsReg.setLayout(new FlowLayout());

jButtonR = new JButton("Register");

jButtonE = new JButton("Edit");

JButton jButtonRe = new JButton("Return");

jButtonR.addActionListener(this);

jButtonE.addActionListener(this);

jButtonRe.addActionListener(this);

buttonsReg.add(jButtonR);

buttonsReg.add(jButtonE);

buttonsReg.add(jButtonRe);

registrationCode.add(buttonsReg);

Box registrationAndPic = Box.createHorizontalBox();

registrationAndPic.add(registrationCode);

jButtonE.setVisible(false);

/*

* image

*/

JLabel imageLabel = new JLabel();

ImageIcon greatwall = new ImageIcon("greatwall.jpg");

imageLabel.setIcon(greatwall);

registrationAndPic.add(imageLabel);

registration.add(registrationAndPic);

return registration;

}

/**

* performe the action which sent by the window.

*

* @param e catch the action event of the window.

*/

public void actionPerformed(ActionEvent e)

{

String actionCommand = e.getActionCommand();

// exit the system

if(actionCommand.equals("Exit"))

System.exit(0);

// return to the calculator

else if(actionCommand.equals("Return"))

{

dealer.show(deckPanel, "cal");

setTitle("Calculator");

validate();

pack();

}

// check the register information

else if(actionCommand.equals("Register"))

{

long check = 0;

Boolean valid = true;

if(nameField.getText().trim().length() != 0)

{

check = calChecksum(nameField.getText().trim());

if(check % 3 != Long.parseLong(first.getText().trim()))

valid = false;

else if(check% 5 != Long.parseLong(second.getText().trim()))

valid = false;

else if(check % 7 != Long.parseLong(third.getText().trim()))

valid = false;

else if(check % 11 != Long.parseLong(fourth.getText().trim()))

valid = false;

// if the information is valid, we will change the buttons

// and set the text field uneditable.

if(valid)

{

jButtonE.setVisible(true);

jButtonR.setVisible(false);

nameField.setEditable(false);

countryField.setEditable(false);

zipField.setEditable(false);

stateField.setEditable(false);

cityField.setEditable(false);

streetAddressField.setEditable(false);

first.setEditable(false);

second.setEditable(false);

third.setEditable(false);

fourth.setEditable(false);

validate();

}

}

}

// make the text field editable

else if(actionCommand.equals("Edit"))

{

jButtonE.setVisible(false);

jButtonR.setVisible(true);

nameField.setEditable(true);

countryField.setEditable(true);

zipField.setEditable(true);

stateField.setEditable(true);

cityField.setEditable(true);

streetAddressField.setEditable(true);

first.setEditable(true);

second.setEditable(true);

third.setEditable(true);

fourth.setEditable(true);

validate();

}

// turn to registration window

else if(actionCommand.equals("Registration Info"))

{

dealer.show(deckPanel, "reg");

setTitle("Registration");

validate();

pack();

}

// turn to scientific model

else if(actionCommand.equals("Scientific Mode"))

{

dealer.show(deckPanel, "cal");

vPanel1.setVisible(scientificMode.isSelected());

mod.setVisible(scientificMode.isSelected());

xey.setVisible(scientificMode.isSelected());

ms.setVisible(scientificMode.isSelected());

mr.setVisible(scientificMode.isSelected());

mc.setVisible(scientificMode.isSelected());

if(scientificMode.isSelected())

setTitle("Scientific Model");

else

setTitle("Normal Model");

validate();

pack();

}

// post the result

else if(actionCommand.equals("="))

{

// if the pre-operated command was "=", return the pre-step

if(!preOperatedCommand.equals("="))

tail = Double.parseDouble(result.getText().trim());

// if the two numbel are 0, we don't need calculate the result

if(tail!= 0.0 || head !=0.0)

{

// division

if(operatedCommand.equals("\u00F7"))

{

if(Math.abs(tail) > 0.0000000000000000001)

{

head = head/tail;

result.setText(Double.toString(head));

}

else

{

JOptionPane.showMessageDialog(this, "Cannot divide by zero.");

head = 0.0;

tail = 0.0;

}

substitution = true;

}

// multiplacation

else if(operatedCommand.equals("\u00d7"))

{

head = head*tail;

result.setText(Double.toString(head));

substitution = true;

}

// sub

else if(operatedCommand.equals("-"))

{

head = head-tail;

result.setText(Double.toString(head));

substitution = true;

}

// plus

else if(operatedCommand.equals("+"))

{

head = head+tail;

result.setText(Double.toString(head));

substitution = true;

}

// pow

else if(operatedCommand.equals("pow"))

{

head = Math.pow(head, tail);

result.setText(Double.toString(head));

substitution = true;

}

// the Yth root of the X

else if(operatedCommand.equals("XeY"))

{

head = Math.pow(head, 1/tail);

result.setText(Double.toString(head));

substitution = true;

}

// modular

else if(operatedCommand.equals("Mod"))

{

head = head % tail;

result.setText(Double.toString(head));

substitution = true;

}

}

preOperatedCommand = "=";

}

/*************************************************************

* set the action of the number

**************************************************************/

else if(actionCommand.equals("0"))

{

if(!(result.getText().equals("0") || result.getText().equals("-0")))

{

if(substitution)

{

result.setText("0");

}

else

result.setText(result.getText() + "0");

}

}

else if(actionCommand.equals("1"))

{

if(substitution)

{

result.setText("1");

substitution = false;

}

else

result.setText(result.getText() + "1");

}

else if(actionCommand.equals("2"))

{

if(substitution)

{

result.setText("2");

substitution = false;

}

else

result.setText(result.getText() + "2");

}

else if(actionCommand.equals("3"))

{

if(substitution)

{

result.setText("3");

substitution = false;

}

else

result.setText(result.getText() + "3");

}

else if(actionCommand.equals("4"))

{

if(substitution)

{

result.setText("4");

substitution = false;

}

else

result.setText(result.getText() + "4");

}

else if(actionCommand.equals("5"))

{

if(substitution)

{

result.setText("5");

substitution = false;

}

else

result.setText(result.getText() + "5");

}

else if(actionCommand.equals("6"))

{

if(substitution)

{

result.setText("6");

substitution = false;

}

else

result.setText(result.getText() + "6");

}

else if(actionCommand.equals("7"))

{

if(substitution)

{

result.setText("7");

substitution = false;

}

else

result.setText(result.getText() + "7");

}

else if(actionCommand.equals("8"))

{

if(substitution)

{

result.setText("8");

substitution = false;

}

else

result.setText(result.getText() + "8");

}

else if(actionCommand.equals("9"))

{

if(substitution)

{

result.setText("9");

substitution = false;

}

else

result.setText(result.getText() + "9");

}

else if(actionCommand.equals("."))

{

if(result.getText().length() == 0)

result.setText("0.");

if(!(result.getText().contains(".")))

result.setText(result.getText() + ".");

}

else if(actionCommand.equals("\u00b1"))

{

if(result.getText().charAt(0) != '-')

result.setText("-" + result.getText());

else

result.setText(result.getText().substring(1));

}

else if(actionCommand.equals("C"))

{

result.setText("0");

substitution = true;

}

/*************************************************************

* set the action of the arithmetic

**************************************************************/

// division

else if(actionCommand.equals("\u00F7"))

{

head = Double.parseDouble(result.getText().trim());

operatedCommand = "\u00F7";

substitution = true;

preOperatedCommand = "\u00F7";

}

// multiplication

else if(actionCommand.equals("\u00d7"))

{

head = Double.parseDouble(result.getText().trim());

operatedCommand = "\u00d7";

substitution = true;

preOperatedCommand = "\u00d7";

}

// sub

else if(actionCommand.equals("-"))

{

head = Double.parseDouble(result.getText().trim());

operatedCommand = "-";

substitution = true;

preOperatedCommand = "-";

}

// plus

else if(actionCommand.equals("+"))

{

head = Double.parseDouble(result.getText().trim());

operatedCommand = "+";

substitution = true;

preOperatedCommand = "+";

}

// backwards

else if(actionCommand.equals("1/X"))

{

head = Double.parseDouble(result.getText().trim());

if(head != 0)

result.setText(Double.toString(1/head));

else

{

JOptionPane.showMessageDialog(this, "Cannot divide by zero.");

head = 0.0;

tail = 0.0;

}

}

// factorial

else if(actionCommand.equals("X!"))

{

head = Double.parseDouble(result.getText().trim());

result.setText(Double.toString(factorial(head)));

}

// square

else if(actionCommand.equals("sqr"))

{

head = Double.parseDouble(result.getText().trim());

result.setText(Double.toString(head*head));

}

// square root

else if(actionCommand.equals("\u221a"))

{

head = Double.parseDouble(result.getText().trim());

if(head >= 0.0)

result.setText(Double.toString(Math.sqrt(head)));

else

{

JOptionPane.showMessageDialog(this, "Invalid input for function");

head = 0.0;

tail = 0.0;

}

}

// power

else if(actionCommand.equals("pow"))

{

head = Double.parseDouble(result.getText().trim());

operatedCommand = "pow";

substitution = true;

preOperatedCommand = "pow";

}

// the Yth of the X

else if(actionCommand.equals("XeY"))

{

head = Double.parseDouble(result.getText().trim());

operatedCommand = "XeY";

substitution = true;

preOperatedCommand = "XeY";

}

// modular

else if(actionCommand.equals("Mod"))

{

head = Double.parseDouble(result.getText().trim());

operatedCommand = "Mod";

substitution = true;

preOperatedCommand = "Mod";

}

// MS

else if(actionCommand.equals("MS"))

{

variableMemory = Double.parseDouble(result.getText().trim());

}

// MR

else if(actionCommand.equals("MR"))

{

result.setText(Double.toString(variableMemory));

}

// MC

else if(actionCommand.equals("MC"))

{

variableMemory = 0.0;

}

}

/**

* calculates and returns the factorial of the value

*

* @param value value of the root of the factorial

*

*/

public double factorial(double value)

{

if(value <= 1.0)

return value;

else

return value*factorial(value-1);

}

/**

* calculates and returns the check sum of the message.

*

* @param message message of the name whick entered by the user.

*/

public long calChecksum(String message)

{

long check=0;

for (int i=0;i<message.length();i++)

check += message.charAt(i);

return check;

}

public static void main(String[] args)

{

Calculator calculator = new Calculator();

calculator.pack();

calculator.setVisible(true);

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有