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

标题  记事本写的科学计算器(源代码)    
关键字  记事本写的科学计算器(源代码)
出处  选择自 hongweijin 的 Blog   作者Blog:http://blog.csdn.net/hongweijin/

ExpandedBlockStart.gif ContractedBlock.gif /** */ /**
InBlock.gif * Calculator
InBlock.gif * A shareware calculator
InBlock.gif *
InBlock.gif * 
@author {@link http://blog.csdn.net/hongweijin Bingbing Li}
InBlock.gif *
InBlock.gif * @recitation 0101 Matt Carlson
InBlock.gif *
InBlock.gif * @date 12/7/2005 12:08AM
InBlock.gif *
ExpandedBlockEnd.gif 
*/

None.gif 
None.gif 
import  javax.swing. * ;
None.gif 
import  javax.swing.border. * ;
None.gif 
import  java.awt. * ;
None.gif 
import  java.awt.event. * ;
None.gif 
None.gif 
public   class  Calculator  extends  JFrame  implements  ActionListener
ExpandedBlockStart.gifContractedBlock.gif 
dot.gif {
InBlock.gif     
public static final int WIDTH = 800;            // width of the window                  
InBlock.gif
     public static final int HEIGHT = 600;           // height of the window                 
InBlock.gif
     public static final int BUTTON_WIDTH = 80;      // width of the buttons                 
InBlock.gif
     public static final int BUTTON_HEIGHT = 60;     // height of the buttons                
InBlock.gif
                                                                                             
InBlock.gif     
private CardLayout dealer;                      // card layout                          
InBlock.gif
     private JPanel        deckPanel;                   // used to card layout                  
InBlock.gif
                                                                                             
InBlock.gif     
private JTextField result;                      // the calculate result                 
InBlock.gif
     private JCheckBoxMenuItem scientificMode;       // the menu item of the mode            
InBlock.gif
                                                                                             
InBlock.gif     
private Box vPanel1;                            // the first line buttons of the        
InBlock.gif                                                        
// scientific mode.                     
InBlock.gif
                                                                                             
InBlock.gif     
private JButton mod;                            // the modular button                   
InBlock.gif
     private JButton xey;                            // the button of Yth root of X          
InBlock.gif
     private JButton ms;                             // save button                          
InBlock.gif
    private JButton mr;                             // release the stored value             
InBlock.gif
     private    JButton mc;                             // clear the stored value               
InBlock.gif
                                                                                             
InBlock.gif     
private double head = 0.0;                      // the first number of the equation     
InBlock.gif
     private double tail = 0.0;                      // the second number of the equation    
InBlock.gif
                                                                                             
InBlock.gif     
private boolean substitution = true;            // whether substituted the answer or not
InBlock.gif
                                                                                             
InBlock.gif     
private String operatedCommand = "NOTHING";     // the current operated command         
InBlock.gif
     private String preOperatedCommand = "NOTHING";  // remember the pre-operated command
InBlock.gif
     
InBlock.gif     
private double variableMemory = 0.0;            // the variable of the memory
InBlock.gif
     
InBlock.gif     
private JButton jButtonR;                       // the register's button
InBlock.gif
     private JButton jButtonE;                       // the edit's button
InBlock.gif
     
InBlock.gif     
private JTextField nameField;                   // the field of the name
InBlock.gif
     private JTextField countryField;                // the field of the country
InBlock.gif
     private JTextField zipField;                    // the field of the zip
InBlock.gif
     private JTextField stateField;                  // the field of the state
InBlock.gif
     private JTextField cityField ;                  // the field of the city
InBlock.gif
     private JTextField streetAddressField;          // the field of the address
InBlock.gif
     
InBlock.gif     
private JTextField first;                       // the first part of the key
InBlock.gif
     private JTextField second;                      // the second part of the key
InBlock.gif
     private JTextField third;                       // the third part of the key
InBlock.gif
     private JTextField fourth;                      // the fourth part of the key
InBlock.gif
     
InBlock.gif     
InBlock.gif     
public Calculator()
ExpandedSubBlockStart.gifContractedSubBlock.gif     
dot.gif{
InBlock.gif         setSize(WIDTH, HEIGHT);
InBlock.gif         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
InBlock.gif         setTitle(
"Normal Calculator");
InBlock.gif         
InBlock.gif         Container contentPre 
= getContentPane();    // the container of the window
InBlock.gif
         
InBlock.gif         dealer 
= new CardLayout();                  // create a new card layout
InBlock.gif
         deckPanel = new JPanel();                    
InBlock.gif         deckPanel.setLayout(dealer);
InBlock.gif         
InBlock.gif         Box content 
= Box.createVerticalBox();      // create a new vertical Box 
InBlock.gif
         
InBlock.gif         Box registration 
= Box.createVerticalBox();
InBlock.gif         
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/** *//****************************************************
InBlock.gif         *    menu
InBlock.gif         *   file
ExpandedSubBlockEnd.gif         ****************************************************
*/

InBlock.gif         JMenu fileMenu 
= new JMenu("File");         
InBlock.gif         JMenuItem exitItemOfFile 
= new JMenuItem("Exit");
InBlock.gif         exitItemOfFile.addActionListener(
this);
InBlock.gif         fileMenu.add(exitItemOfFile);
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/** *//**
InBlock.gif         *    menu
InBlock.gif         *   settings
ExpandedSubBlockEnd.gif         
*/

InBlock.gif         JMenu settingsMenu 
= new JMenu("Settings");
InBlock.gif         JMenuItem registrationInfo 
= new JMenuItem("Registration Info");
InBlock.gif         registrationInfo.addActionListener(
this);
InBlock.gif         settingsMenu.add(registrationInfo);
InBlock.gif         
InBlock.gif         scientificMode 
= new JCheckBoxMenuItem("Scientific Mode");
InBlock.gif         scientificMode.addActionListener(
this);
InBlock.gif         settingsMenu.add(scientificMode);
InBlock.gif         
InBlock.gif         JMenuBar jMenuBar 
= new JMenuBar();
InBlock.gif         jMenuBar.add(fileMenu);
InBlock.gif         jMenuBar.add(settingsMenu);
InBlock.gif         setJMenuBar(jMenuBar);
InBlock.gif         
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/** *//****************************************************
InBlock.gif         *    textFiled panel
ExpandedSubBlockEnd.gif        ****************************************************
*/

InBlock.gif        
InBlock.gif        result 
= new JTextField("0");                     // the initiated value of the answer
InBlock.gif
        result.setBackground(Color.CYAN);                 // set the back ground color with cyan
InBlock.gif
        result.setHorizontalAlignment(JTextField.RIGHT);  // set the horizontal alignment  
InBlock.gif
        
InBlock.gif        
InBlock.gif        content.add(result);
InBlock.gif             
InBlock.gif         content.add(paintButtons());
InBlock.gif         
InBlock.gif         deckPanel.add(
"cal", content);                    // add the calculators card to the layout
InBlock.gif
         
InBlock.gif         registration.add(paintRegistration());            
// add the register window
InBlock.gif
         
InBlock.gif         deckPanel.add(
"reg", registration);               // add the register window to the layout
InBlock.gif
         
InBlock.gif         contentPre.add(deckPanel);                   
// add the cards to the container
ExpandedSubBlockEnd.gif
     }

InBlock.gif     
ExpandedSubBlockStart.gifContractedSubBlock.gif     
/** *//**
InBlock.gif     * paint the buttons of the two models.
InBlock.gif     *
ExpandedSubBlockEnd.gif     
*/

InBlock.gif     
public Box paintButtons() 
ExpandedSubBlockStart.gifContractedSubBlock.gif     
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/** *//****************************************************
InBlock.gif        *    Buttons
ExpandedSubBlockEnd.gif        ****************************************************
*/

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/** *//**
InBlock.gif         *    line1
ExpandedSubBlockEnd.gif         
*/
 
InBlock.gif         vPanel1 
= Box.createVerticalBox();                                      
InBlock.gif         
InBlock.gif         
// add the backwards's button                                                                           
InBlock.gif
         JButton backwards = new JButton("1/X");                                     
InBlock.gif         backwards.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));       
InBlock.gif         backwards.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));     
InBlock.gif         backwards.addActionListener(
this);                                          
InBlock.gif         vPanel1.add(backwards);    
InBlock.gif                                                          
InBlock.gif         
// add the factorial button                                                                            
InBlock.gif
         JButton factorial = new JButton("X!");                                      
InBlock.gif         factorial.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));       
InBlock.gif         factorial.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));     
InBlock.gif         factorial.addActionListener(
this);                                          
InBlock.gif         vPanel1.add(factorial);                                                     
InBlock.gif         
InBlock.gif         
// add the square's button                                                                            
InBlock.gif
         JButton square = new JButton("<html>X<sup>2</sup></html>");                 
InBlock.gif         square.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));          
InBlock.gif         square.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));        
InBlock.gif         square.addActionListener(
this);
InBlock.gif         square.setActionCommand(
"sqr");                                             
InBlock.gif         vPanel1.add(square);                                                        
InBlock.gif         
InBlock.gif         
// add the square root's button                                                                            
InBlock.gif
         JButton squareRoot = new JButton("\u221a");                                 
InBlock.gif         squareRoot.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));      
InBlock.gif         squareRoot.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));    
InBlock.gif         squareRoot.addActionListener(
this);                                         
InBlock.gif         vPanel1.add(squareRoot);                                                    
InBlock.gif               
InBlock.gif         
// add the power's button                                                                       
InBlock.gif
         JButton power = new JButton("<html>X<sup>Y</sup></html>");                  
InBlock.gif         power.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));           
InBlock.gif         power.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));         
InBlock.gif         power.addActionListener(
this);   
InBlock.gif         power.setActionCommand(
"pow");                                           
InBlock.gif         vPanel1.add(power);                                                         
InBlock.gif                  
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/** *//**
InBlock.gif         *    line2
ExpandedSubBlockEnd.gif         
*/

InBlock.gif         Box vPanel2 
= Box.createVerticalBox();
InBlock.gif         
InBlock.gif         
// add the modular button 
InBlock.gif
         mod = new JButton("Mod");
InBlock.gif         mod.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         mod.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         mod.addActionListener(
this);
InBlock.gif         vPanel2.add(mod);
InBlock.gif                  
InBlock.gif         
// add the seven button 
InBlock.gif
         JButton seven = new JButton("7");
InBlock.gif         seven.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         seven.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         seven.addActionListener(
this);
InBlock.gif         vPanel2.add(seven); 
InBlock.gif         
InBlock.gif         
// add the four button 
InBlock.gif
         JButton four = new JButton("4");
InBlock.gif         four.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         four.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         four.addActionListener(
this);
InBlock.gif         vPanel2.add(four); 
InBlock.gif         
InBlock.gif         
// add the one button 
InBlock.gif
         JButton one = new JButton("1");
InBlock.gif         one.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         one.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         one.addActionListener(
this);
InBlock.gif         vPanel2.add(one); 
InBlock.gif         
InBlock.gif         
// add the zero button 
InBlock.gif
         JButton zero = new JButton("0");
InBlock.gif         zero.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         zero.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         zero.addActionListener(
this);
InBlock.gif         vPanel2.add(zero);
InBlock.gif         
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/** *//**
InBlock.gif         *    line3
ExpandedSubBlockEnd.gif         
*/

InBlock.gif         Box vPanel3 
= Box.createVerticalBox();
InBlock.gif         
InBlock.gif         
// add the Yth root of X button 
InBlock.gif
         xey = new JButton("XeY");
InBlock.gif         xey.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         xey.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         xey.addActionListener(
this);
InBlock.gif         vPanel3.add(xey);
InBlock.gif              
InBlock.gif          
// add the eight button 
InBlock.gif
         JButton eight = new JButton("8");
InBlock.gif         eight.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif        eight.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         eight.addActionListener(
this);
InBlock.gif         vPanel3.add(eight); 
InBlock.gif         
InBlock.gif         
// add the five button 
InBlock.gif
         JButton five = new JButton("5");
InBlock.gif         five.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         five.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         five.addActionListener(
this);
InBlock.gif         vPanel3.add(five); 
InBlock.gif         
InBlock.gif         
// add the two button 
InBlock.gif
         JButton two = new JButton("2");
InBlock.gif         two.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         two.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         two.addActionListener(
this);
InBlock.gif         vPanel3.add(two); 
InBlock.gif         
InBlock.gif         
// add the dot button 
InBlock.gif
         JButton dot = new JButton(".");
InBlock.gif         dot.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         dot.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         dot.addActionListener(
this);
InBlock.gif         vPanel3.add(dot);      
InBlock.gif         
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/** *//**
InBlock.gif         *    line4
ExpandedSubBlockEnd.gif         
*/

InBlock.gif         Box vPanel4 
= Box.createVerticalBox();
InBlock.gif         
InBlock.gif         
// add the MS button 
InBlock.gif
         ms = new JButton("MS");
InBlock.gif         ms.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif        ms.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         ms.addActionListener(
this);
InBlock.gif         vPanel4.add(ms);
InBlock.gif             
InBlock.gif         
// add the nine button 
InBlock.gif
         JButton nine = new JButton("9");
InBlock.gif         nine.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         nine.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         nine.addActionListener(
this);
InBlock.gif         vPanel4.add(nine); 
InBlock.gif         
InBlock.gif         
// add the six button 
InBlock.gif
         JButton six = new JButton("6");
InBlock.gif         six.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         six.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         six.addActionListener(
this);
InBlock.gif         vPanel4.add(six); 
InBlock.gif         
InBlock.gif         
// add the three button 
InBlock.gif
         JButton three = new JButton("3");
InBlock.gif         three.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         three.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         three.addActionListener(
this);
InBlock.gif         vPanel4.add(three); 
InBlock.gif         
InBlock.gif         
// add the plusMinus button 
InBlock.gif
         JButton plusMinus = new JButton("\u00b1");
InBlock.gif         plusMinus.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         plusMinus.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         plusMinus.addActionListener(
this);
InBlock.gif         vPanel4.add(plusMinus);     
InBlock.gif         
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/** *//**
InBlock.gif         *    line5
ExpandedSubBlockEnd.gif         
*/

InBlock.gif         Box vPanel5 
= Box.createVerticalBox();
InBlock.gif         
InBlock.gif         
// add the MR button 
InBlock.gif
         mr = new JButton("MR");
InBlock.gif         mr.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         mr.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         mr.addActionListener(
this);
InBlock.gif         vPanel5.add(mr);
InBlock.gif         
InBlock.gif         
// add the division button 
InBlock.gif
         JButton division = new JButton("\u00F7");
InBlock.gif         division.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         division.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         division.addActionListener(
this);
InBlock.gif         vPanel5.add(division); 
InBlock.gif         
InBlock.gif         
// add the multiplication button 
InBlock.gif
         JButton multiplication = new JButton("\u00d7");
InBlock.gif         multiplication.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         multiplication.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         multiplication.addActionListener(
this);
InBlock.gif         vPanel5.add(multiplication); 
InBlock.gif         
InBlock.gif         
// add the subtract button 
InBlock.gif
         JButton subtract = new JButton("-");
InBlock.gif         subtract.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         subtract.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         subtract.addActionListener(
this);
InBlock.gif         vPanel5.add(subtract); 
InBlock.gif         
InBlock.gif         
// add the plus button 
InBlock.gif
         JButton plus = new JButton("+");
InBlock.gif         plus.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         plus.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         plus.addActionListener(
this);
InBlock.gif         vPanel5.add(plus);     
InBlock.gif         
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/** *//**
InBlock.gif         *    line6
ExpandedSubBlockEnd.gif         
*/

InBlock.gif         Box vPanel6 
= Box.createVerticalBox();
InBlock.gif         
InBlock.gif         
// add the MC button 
InBlock.gif
         mc = new JButton("MC");
InBlock.gif         mc.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         mc.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         mc.addActionListener(
this);
InBlock.gif         vPanel6.add(mc);
InBlock.gif             
InBlock.gif         
// add the C button 
InBlock.gif
         JButton c = new JButton("C");
InBlock.gif         c.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         c.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
InBlock.gif         c.addActionListener(
this);
InBlock.gif         vPanel6.add(c); 
InBlock.gif         
InBlock.gif         
// add a vertical strut 
InBlock.gif
         Component verticalStrut =
InBlock.gif             Box.createVerticalStrut(BUTTON_HEIGHT);
InBlock.gif         vPanel6.add(verticalStrut);
InBlock.gif         
InBlock.gif         
// add the enter button 
InBlock.gif
         JButton enter = new JButton("=");
InBlock.gif         enter.setMaximumSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT * 2));
InBlock.gif         enter.setPreferredSize(
new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT * 2));
InBlock.gif         enter.addActionListener(
this);
InBlock.gif         vPanel6.add(enter); 
InBlock.gif         
InBlock.gif          
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/** *//**
InBlock.gif         *    Buttons panel
ExpandedSubBlockEnd.gif         
*/

InBlock.gif         Box buttonsPanel 
= Box.createHorizontalBox();
InBlock.gif         
InBlock.gif         buttonsPanel.add(vPanel1);
InBlock.gif         buttonsPanel.add(vPanel2);
InBlock.gif         buttonsPanel.add(vPanel3);
InBlock.gif         buttonsPanel.add(vPanel4);
InBlock.gif         buttonsPanel.add(vPanel5);
InBlock.gif         buttonsPanel.add(vPanel6);
InBlock.gif         
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/** *//**********************************************************
InBlock.gif         *    the initial state is normal calculator
ExpandedSubBlockEnd.gif         **********************************************************
*/

InBlock.gif         vPanel1.setVisible(
false);
InBlock.gif         mod.setVisible(
false);
InBlock.gif         xey.setVisible(
false);
InBlock.gif         ms.setVisible(
false);
InBlock.gif         mr.setVisible(
false);
InBlock.gif         mc.setVisible(
false);
InBlock.gif              
InBlock.gif         
return buttonsPanel;    
ExpandedSubBlockEnd.gif     }

InBlock.gif     
ExpandedSubBlockStart.gifContractedSubBlock.gif     
/** *//**
InBlock.gif     * paint the registration window.
InBlock.gif     *
ExpandedSubBlockEnd.gif     
*/

InBlock.gif     
public Box paintRegistration()
ExpandedSubBlockStart.gifContractedSubBlock.gif     
dot.gif{
InBlock.gif         Box registration 
= Box.createVerticalBox();
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**//*
InBlock.gif         *    title
ExpandedSubBlockEnd.gif         
*/

InBlock.gif         JLabel titleRegistration 
= new JLabel("Bingbing's Calculator Registration");
InBlock.gif         registration.add(titleRegistration);
InBlock.gif         
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**//*
InBlock.gif         *    information
ExpandedSubBlockEnd.gif         
*/

InBlock.gif         JPanel information 
= new JPanel();
InBlock.gif         information.setLayout(
new GridLayout(62));
InBlock.gif         
//Name
InBlock.gif
         JLabel name = new JLabel("Name:");
InBlock.gif         nameField 
= new JTextField();
InBlock.gif         information.add(name);
InBlock.gif         information.add(nameField);
InBlock.gif         
//Street Address
InBlock.gif
         JLabel streetAddress = new JLabel("Street Address:");
InBlock.gif         streetAddressField 
= new JTextField();
InBlock.gif         information.add(streetAddress);
InBlock.gif         information.add(streetAddressField);
InBlock.gif         
//City
InBlock.gif
         JLabel city = new JLabel("City:");
InBlock.gif         cityField 
= new JTextField();
InBlock.gif         information.add(city);
InBlock.gif         information.add(cityField);
InBlock.gif         
//State
InBlock.gif
         JLabel state = new JLabel("State:");
InBlock.gif         stateField 
= new JTextField();
InBlock.gif         information.add(state);
InBlock.gif         information.add(stateField);
InBlock.gif         
//Zip
InBlock.gif
         JLabel zip = new JLabel("Zip:");
InBlock.gif         zipField 
= new JTextField();
InBlock.gif         information.add(zip);
InBlock.gif         information.add(zipField);
InBlock.gif         
//Country
InBlock.gif
         JLabel country = new JLabel("Country:");
InBlock.gif         countryField 
= new JTextField();
InBlock.gif         information.add(country);
InBlock.gif         information.add(countryField);
InBlock.gif         
InBlock.gif         registration.add(information);
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**//*
InBlock.gif         *    Registration Code
ExpandedSubBlockEnd.gif         
*/
    
InBlock.gif         Box registrationCode 
= Box.createVerticalBox();
InBlock.gif         
InBlock.gif         JPanel registrationCodePanel 
= new JPanel();
InBlock.gif         registrationCodePanel.setLayout(
new FlowLayout());
InBlock.gif         
InBlock.gif         
//registrationCodePanel.setTitle("Registration Code");
InBlock.gif
         registrationCodePanel.setBorder(new LineBorder(Color.red, 1));
InBlock.gif         registrationCode.add(registrationCodePanel);
InBlock.gif         
InBlock.gif         first 
= new JTextField(3);
InBlock.gif         registrationCodePanel.add(first);
InBlock.gif         JLabel rail1 
= new JLabel(" - ");
InBlock.gif         registrationCodePanel.add(rail1);
InBlock.gif         
InBlock.gif         second 
= new JTextField(3);
InBlock.gif         registrationCodePanel.add(second);
InBlock.gif         JLabel rail2 
= new JLabel(" - ");
InBlock.gif         registrationCodePanel.add(rail2);
InBlock.gif         
InBlock.gif         third 
= new JTextField(3);
InBlock.gif         JLabel rail3 
= new JLabel(" - ");
InBlock.gif         registrationCodePanel.add(third);
InBlock.gif         registrationCodePanel.add(rail3);
InBlock.gif         
InBlock.gif         fourth 
= new JTextField(3);
InBlock.gif         registrationCodePanel.add(fourth);
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**//*
InBlock.gif         *    buttons
ExpandedSubBlockEnd.gif         
*/

InBlock.gif         JPanel buttonsReg 
= new JPanel();
InBlock.gif         buttonsReg.setLayout(
new FlowLayout());
InBlock.gif         
InBlock.gif         jButtonR 
= new JButton("Register");
InBlock.gif         jButtonE 
= new JButton("Edit");
InBlock.gif         JButton jButtonRe 
= new JButton("Return");
InBlock.gif         jButtonR.addActionListener(
this);
InBlock.gif         jButtonE.addActionListener(
this);
InBlock.gif         jButtonRe.addActionListener(
this);
InBlock.gif         buttonsReg.add(jButtonR);
InBlock.gif         buttonsReg.add(jButtonE);
InBlock.gif         buttonsReg.add(jButtonRe);
InBlock.gif         
InBlock.gif         registrationCode.add(buttonsReg);
InBlock.gif         
InBlock.gif         Box registrationAndPic 
= Box.createHorizontalBox();
InBlock.gif         
InBlock.gif         registrationAndPic.add(registrationCode);
InBlock.gif         
InBlock.gif         jButtonE.setVisible(
false);
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**//*
InBlock.gif         *    image
ExpandedSubBlockEnd.gif         
*/

InBlock.gif         JLabel imageLabel 
= new JLabel();
InBlock.gif         ImageIcon greatwall 
= new ImageIcon("greatwall.jpg");
InBlock.gif         imageLabel.setIcon(greatwall);
InBlock.gif         registrationAndPic.add(imageLabel);
InBlock.gif         
InBlock.gif         registration.add(registrationAndPic);
InBlock.gif         
InBlock.gif         
return registration;    
ExpandedSubBlockEnd.gif     }

InBlock.gif     
ExpandedSubBlockStart.gifContractedSubBlock.gif     
/** *//**
InBlock.gif     * performe the action which sent by the window.
InBlock.gif     *
InBlock.gif     * 
@param e catch the action event of the window.
ExpandedSubBlockEnd.gif     
*/

InBlock.gif     
public void actionPerformed(ActionEvent e)
ExpandedSubBlockStart.gifContractedSubBlock.gif     
dot.gif{
InBlock.gif         String actionCommand 
= e.getActionCommand();
InBlock.gif         
InBlock.gif                
// exit the system
InBlock.gif
         if(actionCommand.equals("Exit"))
InBlock.gif             System.exit(
0);
InBlock.gif                
InBlock.gif                
// return to the calculator
InBlock.gif
         else if(actionCommand.equals("Return"))
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif             dealer.show(deckPanel, 
"cal");
InBlock.gif             setTitle(
"Calculator");
InBlock.gif             validate();
InBlock.gif             pack();        
ExpandedSubBlockEnd.gif         }

InBlock.gif                
// check the register information
InBlock.gif
         else if(actionCommand.equals("Register"))
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{        
InBlock.gif             
long check = 0;
InBlock.gif             Boolean valid 
= true;
InBlock.gif             
InBlock.gif             
if(nameField.getText().trim().length() != 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif             
dot.gif{
InBlock.gif                check 
= calChecksum(nameField.getText().trim());            
InBlock.gif              
InBlock.gif                  
if(check % 3 != Long.parseLong(first.getText().trim()))
InBlock.gif                      valid 
= false;
InBlock.gif                  
else if(check% 5 != Long.parseLong(second.getText().trim()))
InBlock.gif                      valid 
= false;
InBlock.gif                  
else if(check % 7 != Long.parseLong(third.getText().trim()))
InBlock.gif                      valid 
= false;
InBlock.gif                  
else if(check % 11 != Long.parseLong(fourth.getText().trim()))
InBlock.gif                      valid 
= false;
InBlock.gif              
InBlock.gif                  
// if the information is valid, we will change the buttons
InBlock.gif                        
// and set the text field uneditable.
InBlock.gif
                        if(valid)
ExpandedSubBlockStart.gifContractedSubBlock.gif                  
dot.gif{
InBlock.gif                      jButtonE.setVisible(
true);
InBlock.gif                      jButtonR.setVisible(
false);
InBlock.gif                      
InBlock.gif                      nameField.setEditable(
false);        
InBlock.gif                      countryField.setEditable(
false);     
InBlock.gif                      zipField.setEditable(
false);         
InBlock.gif                      stateField.setEditable(
false);       
InBlock.gif                      cityField.setEditable(
false);       
InBlock.gif                      streetAddressField.setEditable(
false);    
InBlock.gif                      
InBlock.gif                      first.setEditable(
false);
InBlock.gif                      second.setEditable(
false);
InBlock.gif                      third.setEditable(
false); 
InBlock.gif                      fourth.setEditable(
false);
InBlock.gif                      
InBlock.gif                      validate();
ExpandedSubBlockEnd.gif                  }

ExpandedSubBlockEnd.gif              }

InBlock.gif                  
ExpandedSubBlockEnd.gif         }

InBlock.gif                
// make the text field editable
InBlock.gif
         else if(actionCommand.equals("Edit"))
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif             jButtonE.setVisible(
false);
InBlock.gif              jButtonR.setVisible(
true);
InBlock.gif                  
InBlock.gif              nameField.setEditable(
true);        
InBlock.gif              countryField.setEditable(
true);     
InBlock.gif              zipField.setEditable(
true);         
InBlock.gif              stateField.setEditable(
true);       
InBlock.gif              cityField.setEditable(
true);       
InBlock.gif              streetAddressField.setEditable(
true);    
InBlock.gif              
InBlock.gif              first.setEditable(
true);
InBlock.gif              second.setEditable(
true);
InBlock.gif              third.setEditable(
true); 
InBlock.gif              fourth.setEditable(
true);
InBlock.gif              validate();    
ExpandedSubBlockEnd.gif         }

InBlock.gif         
// turn to registration window
InBlock.gif
         else if(actionCommand.equals("Registration Info"))
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif             dealer.show(deckPanel, 
"reg");
InBlock.gif             
InBlock.gif             setTitle(
"Registration");
InBlock.gif             validate();
InBlock.gif             pack();    
ExpandedSubBlockEnd.gif         }

InBlock.gif                
// turn to scientific model
InBlock.gif
         else if(actionCommand.equals("Scientific Mode"))
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            dealer.show(deckPanel, 
"cal");
InBlock.gif            
InBlock.gif            vPanel1.setVisible(scientificMode.isSelected());
InBlock.gif             mod.setVisible(scientificMode.isSelected());
InBlock.gif             xey.setVisible(scientificMode.isSelected());
InBlock.gif             ms.setVisible(scientificMode.isSelected());
InBlock.gif             mr.setVisible(scientificMode.isSelected());
InBlock.gif             mc.setVisible(scientificMode.isSelected());
InBlock.gif             
if(scientificMode.isSelected())
InBlock.gif                 setTitle(
"Scientific Model");
InBlock.gif             
else
InBlock.gif                 setTitle(
"Normal Model");
InBlock.gif            validate();
InBlock.gif            pack();
ExpandedSubBlockEnd.gif        }

InBlock.gif                
// post the result
InBlock.gif
        else if(actionCommand.equals("="))
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif                        
// if the pre-operated command was "=", return the pre-step
InBlock.gif
             if(!preOperatedCommand.equals("="))
InBlock.gif                 tail 
= Double.parseDouble(result.getText().trim());
InBlock.gif
InBlock.gif             
// if the two numbel are 0, we don't need calculate the result    
InBlock.gif
             if(tail!= 0.0 || head !=0.0)
ExpandedSubBlockStart.gifContractedSubBlock.gif             
dot.gif{
InBlock.gif                 
// division
InBlock.gif
                                if(operatedCommand.equals("\u00F7"))
ExpandedSubBlockStart.gifContractedSubBlock.gif                 
dot.gif{
InBlock.gif                     
if(Math.abs(tail) > 0.0000000000000000001)
ExpandedSubBlockStart.gifContractedSubBlock.gif                     
dot.gif{
InBlock.gif                         head 
= head/tail;
InBlock.gif                         result.setText(Double.toString(head));
ExpandedSubBlockEnd.gif                     }

InBlock.gif                     
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                     
dot.gif{
InBlock.gif                         JOptionPane.showMessageDialog(
this"Cannot divide by zero.");
InBlock.gif                         head 
= 0.0;
InBlock.gif                         tail 
= 0.0;
ExpandedSubBlockEnd.gif                     }

InBlock.gif                     substitution 
= true;
ExpandedSubBlockEnd.gif                 }

InBlock.gif                                
// multiplacation
InBlock.gif
                 else if(operatedCommand.equals("\u00d7"))
ExpandedSubBlockStart.gifContractedSubBlock.gif                 
dot.gif{
InBlock.gif                     head 
= head*tail;
InBlock.gif                     result.setText(Double.toString(head));
InBlock.gif                     substitution 
= true;
ExpandedSubBlockEnd.gif                 }

InBlock.gif                                
// sub
InBlock.gif
                 else if(operatedCommand.equals("-"))
ExpandedSubBlockStart.gifContractedSubBlock.gif                 
dot.gif{
InBlock.gif                     head 
= head-tail;
InBlock.gif                     result.setText(Double.toString(head));
InBlock.gif                     substitution 
= true;
ExpandedSubBlockEnd.gif                 }

InBlock.gif                                
// plus
InBlock.gif
                 else if(operatedCommand.equals("+"))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                     head 
= head+tail;
InBlock.gif                     result.setText(Double.toString(head));
InBlock.gif                     substitution 
= true;
ExpandedSubBlockEnd.gif                 }

InBlock.gif                                
// pow
InBlock.gif
                 else if(operatedCommand.equals("pow"))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    head 
= Math.pow(head, tail);
InBlock.gif                    result.setText(Double.toString(head));
InBlock.gif                     substitution 
= true;
ExpandedSubBlockEnd.gif                }

InBlock.gif                                
// the Yth root of the X
InBlock.gif
                else if(operatedCommand.equals("XeY"))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    head 
= Math.pow(head, 1/tail);
InBlock.gif                    result.setText(Double.toString(head));
InBlock.gif                     substitution 
= true;    
ExpandedSubBlockEnd.gif                }

InBlock.gif                                
// modular
InBlock.gif
                else if(operatedCommand.equals("Mod"))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    head 
= head % tail;
InBlock.gif                    result.setText(Double.toString(head));
InBlock.gif                     substitution 
= true;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif             }

InBlock.gif             preOperatedCommand 
= "=";
ExpandedSubBlockEnd.gif         }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/** *//*************************************************************
InBlock.gif        *    set the action of the number
ExpandedSubBlockEnd.gif        *************************************************************
*/

InBlock.gif        
else if(actionCommand.equals("0"))
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(!(result.getText().equals("0"|| result.getText().equals("-0")))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(substitution)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    result.setText(
"0");
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
InBlock.gif                    result.setText(result.getText() 
+ "0");
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
else if(actionCommand.equals("1"))
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(substitution)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                result.setText(
"1");
InBlock.gif                substitution 
= false;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
InBlock.gif                result.setText(result.getText() 
+ "1");
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else if(actionCommand.equals("2"))
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(substitution)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                result.setText(
"2");
InBlock.gif                substitution 
= false;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
InBlock.gif                result.setText(result.getText() 
+ "2");
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else if(actionCommand.equals("3"))
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(substitution)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                result.setText(
"3");
InBlock.gif                substitution 
= false;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
InBlock.gif                result.setText(result.getText() 
+ "3");
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else if(actionCommand.equals("4"))
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(substitution)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                result.setText(
"4");
InBlock.gif                substitution 
= false;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
InBlock.gif                result.setText(result.getText() 
+ "4");
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else if(actionCommand.equals("5"))
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(substitution)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                result.setText(
"5");
InBlock.gif                substitution 
= false;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
InBlock.gif                result.setText(result.getText() 
+ "5");
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else if(actionCommand.equals("6"))
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(substitution)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                result.setText(
"6");
InBlock.gif                substitution 
= false;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
InBlock.gif                result.setText(result.getText() 
+ "6");
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else if(actionCommand.equals("7"))
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(substitution)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                result.setText(
"7");
InBlock.gif                substitution 
= false;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
InBlock.gif                result.setText(result.getText() 
+ "7");
ExpandedSubBlockEnd.gif        }

InBlock.gif         
else if(actionCommand.equals("8"))
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif            
if(substitution)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                result.setText(
"8");
InBlock.gif                substitution 
= false;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
InBlock.gif                result.setText(result.getText() 
+ "8");
ExpandedSubBlockEnd.gif        }

InBlock.gif         
else if(actionCommand.equals("9"))
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif            
if(substitution)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                result.setText(
"9");
InBlock.gif                substitution 
= false;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
InBlock.gif                result.setText(result.getText() 
+ "9");
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else if(actionCommand.equals("."))
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(result.getText().length() == 0)
InBlock.gif                result.setText(
"0.");
InBlock.gif                
InBlock.gif            
if(!(result.getText().contains(".")))
InBlock.gif                result.setText(result.getText() 
+ ".");
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else if(actionCommand.equals("\u00b1"))
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(result.getText().charAt(0!= '-')
InBlock.gif                result.setText(
"-" + result.getText());
InBlock.gif            
else
InBlock.gif                result.setText(result.getText().substring(
1));
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else if(actionCommand.equals("C"))
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            result.setText(
"0");
InBlock.gif            substitution 
= true;
ExpandedSubBlockEnd.gif        }

InBlock.gif         
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/** *//*************************************************************
InBlock.gif        *    set the action of the arithmetic
ExpandedSubBlockEnd.gif        *************************************************************
*/

InBlock.gif         
// division
InBlock.gif
         else if(actionCommand.equals("\u00F7"))
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif             head 
= Double.parseDouble(result.getText().trim());
InBlock.gif             operatedCommand 
= "\u00F7";
InBlock.gif             substitution 
= true;
InBlock.gif             preOperatedCommand 
= "\u00F7";
ExpandedSubBlockEnd.gif         }

InBlock.gif         
// multiplication
InBlock.gif
         else if(actionCommand.equals("\u00d7"))
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif             head 
= Double.parseDouble(result.getText().trim());
InBlock.gif             operatedCommand 
= "\u00d7";
InBlock.gif             substitution 
= true;
InBlock.gif             preOperatedCommand 
= "\u00d7";
ExpandedSubBlockEnd.gif         }

InBlock.gif                
// sub
InBlock.gif
         else if(actionCommand.equals("-"))
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif             head 
= Double.parseDouble(result.getText().trim());
InBlock.gif             operatedCommand 
= "-";
InBlock.gif             substitution 
= true;
InBlock.gif             preOperatedCommand 
= "-";
ExpandedSubBlockEnd.gif         }

InBlock.gif                
// plus
InBlock.gif
         else if(actionCommand.equals("+"))
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif             head 
= Double.parseDouble(result.getText().trim());
InBlock.gif             operatedCommand 
= "+";
InBlock.gif             substitution 
= true;
InBlock.gif             preOperatedCommand 
= "+";
ExpandedSubBlockEnd.gif         }

InBlock.gif                
// backwards
InBlock.gif
         else if(actionCommand.equals("1/X"))
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif             head 
= Double.parseDouble(result.getText().trim());
InBlock.gif             
if(head != 0)
InBlock.gif                 result.setText(Double.toString(
1/head));     
InBlock.gif             
else
ExpandedSubBlockStart.gifContractedSubBlock.gif             
dot.gif{
InBlock.gif                 JOptionPane.showMessageDialog(
this"Cannot divide by zero.");
InBlock.gif                 head 
= 0.0;
InBlock.gif                 tail 
= 0.0;
ExpandedSubBlockEnd.gif             }

ExpandedSubBlockEnd.gif         }

InBlock.gif                
// factorial
InBlock.gif
         else if(actionCommand.equals("X!"))
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif             head 
= Double.parseDouble(result.getText().trim());
InBlock.gif             result.setText(Double.toString(factorial(head)));    
ExpandedSubBlockEnd.gif         }

InBlock.gif                
// square
InBlock.gif
         else if(actionCommand.equals("sqr"))
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif             head 
= Double.parseDouble(result.getText().trim());
InBlock.gif             result.setText(Double.toString(head
*head));    
ExpandedSubBlockEnd.gif         }

InBlock.gif                
// square root  
InBlock.gif
         else if(actionCommand.equals("\u221a"))
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif             head 
= Double.parseDouble(result.getText().trim());
InBlock.gif             
if(head >= 0.0)
InBlock.gif                 result.setText(Double.toString(Math.sqrt(head)));     
InBlock.gif             
else
ExpandedSubBlockStart.gifContractedSubBlock.gif             
dot.gif{
InBlock.gif                 JOptionPane.showMessageDialog(
this"Invalid input for function");
InBlock.gif                 head 
= 0.0;
InBlock.gif                 tail 
= 0.0;
ExpandedSubBlockEnd.gif             }
    
ExpandedSubBlockEnd.gif         }

InBlock.gif                
// power
InBlock.gif
         else if(actionCommand.equals("pow"))
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif             head 
= Double.parseDouble(result.getText().trim());
InBlock.gif             operatedCommand 
= "pow";
InBlock.gif             substitution 
= true;
InBlock.gif             preOperatedCommand 
= "pow";
ExpandedSubBlockEnd.gif         }

InBlock.gif                
// the Yth of the X
InBlock.gif
         else if(actionCommand.equals("XeY"))
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif             head 
= Double.parseDouble(result.getText().trim());
InBlock.gif             operatedCommand 
= "XeY";
InBlock.gif             substitution 
= true;
InBlock.gif             preOperatedCommand 
= "XeY";    
ExpandedSubBlockEnd.gif         }

InBlock.gif                
// modular
InBlock.gif
         else if(actionCommand.equals("Mod"))
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif             head 
= Double.parseDouble(result.getText().trim());
InBlock.gif             operatedCommand 
= "Mod";
InBlock.gif             substitution 
= true;
InBlock.gif             preOperatedCommand 
= "Mod";    
ExpandedSubBlockEnd.gif         }

InBlock.gif                
// MS
InBlock.gif
         else if(actionCommand.equals("MS"))
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif             variableMemory 
= Double.parseDouble(result.getText().trim());
ExpandedSubBlockEnd.gif         }

InBlock.gif                
// MR
InBlock.gif
         else if(actionCommand.equals("MR"))
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif             result.setText(Double.toString(variableMemory));    
ExpandedSubBlockEnd.gif         }

InBlock.gif                
// MC
InBlock.gif
         else if(actionCommand.equals("MC"))
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif             variableMemory 
= 0.0;    
ExpandedSubBlockEnd.gif         }
 
InBlock.gif         
ExpandedSubBlockEnd.gif     }

ExpandedSubBlockStart.gifContractedSubBlock.gif     
/** *//**
InBlock.gif     * calculates and returns the factorial of the value
InBlock.gif     *
InBlock.gif     * 
@param value value of the root of the factorial
InBlock.gif     *
ExpandedSubBlockEnd.gif     
*/

InBlock.gif     
public double factorial(double value)
ExpandedSubBlockStart.gifContractedSubBlock.gif     
dot.gif{
InBlock.gif         
if(value <= 1.0)
InBlock.gif             
return value;
InBlock.gif         
else
InBlock.gif             
return value*factorial(value-1);    
ExpandedSubBlockEnd.gif     }
 
ExpandedSubBlockStart.gifContractedSubBlock.gif     
/** *//**
InBlock.gif     * calculates and returns the check sum of the message.
InBlock.gif     *
InBlock.gif     * 
@param message message of the name whick entered by the user.
ExpandedSubBlockEnd.gif     
*/

InBlock.gif     
public long calChecksum(String message)
ExpandedSubBlockStart.gifContractedSubBlock.gif     
dot.gif{
InBlock.gif         
long check=0;
InBlock.gif         
InBlock.gif         
for (int i=0;i<message.length();i++)
InBlock.gif                  check 
+= message.charAt(i);     
InBlock.gif          
return check;    
ExpandedSubBlockEnd.gif     }

InBlock.gif     
InBlock.gif     
public static void main(String[] args)
ExpandedSubBlockStart.gifContractedSubBlock.gif     
dot.gif{
InBlock.gif         Calculator calculator 
= new Calculator();
InBlock.gif         calculator.pack();
InBlock.gif         calculator.setVisible(
true);    
ExpandedSubBlockEnd.gif     }

ExpandedBlockEnd.gif }

None.gif

转载于:https://www.cnblogs.com/grandydong/archive/2007/03/06/665435.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值