/**
* 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);
* 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);