Important alert: (current site time 7/15/2013 3:11:59 PM EDT)
 

VB icon

Calculator -2 Methods

Email
Submitted on: 7/27/2003 8:34:39 PM
By: Zachary Bender 
Level: Beginner
User Rating: By 1 Users
Compatibility: Java (JDK 1.2)
Views: 19152
author picture
 
     I helped make this to learn and teach two methods to working with numbers.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: Calculator -2 Methods
// Description:I helped make this to learn and teach two methods to working with numbers.
// By: Zachary Bender
//
// Inputs:2 numbers
//
// Returns:1 Return/2 returns
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=3776&lngWId=2//for details.//**************************************

public class Chardonnay extends javax.swing.JFrame {
/** Creates new form Chardonnay */
public Chardonnay() {
 initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
 groupOperator = new javax.swing.ButtonGroup();
 jPanel1 = new javax.swing.JPanel();
 labelResult = new javax.swing.JLabel();
 radioDivide = new javax.swing.JRadioButton();
 radioMultiply = new javax.swing.JRadioButton();
 radioSubtract = new javax.swing.JRadioButton();
 radioAdd = new javax.swing.JRadioButton();
 editY = new javax.swing.JTextField();
 editX = new javax.swing.JTextField();
 jLabel11 = new javax.swing.JLabel();
 jLabel1 = new javax.swing.JLabel();
 buttonDoIt = new javax.swing.JButton();
 buttonDoIt2 = new javax.swing.JButton();
 radioSqu = new javax.swing.JRadioButton();
 labelResult2 = new javax.swing.JLabel();
 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
 setTitle("Mathio");
 addWindowListener(new java.awt.event.WindowAdapter() {
 public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
 }
 public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
 }
 });
 jPanel1.setLayout(null);
 labelResult.setForeground(new java.awt.Color(0, 51, 255));
 labelResult.setText("Result");
 jPanel1.add(labelResult);
 labelResult.setBounds(20, 180, 110, 16);
 radioDivide.setText("Divide");
 groupOperator.add(radioDivide);
 jPanel1.add(radioDivide);
 radioDivide.setBounds(10, 130, 74, 24);
 radioMultiply.setText("Multiply");
 groupOperator.add(radioMultiply);
 jPanel1.add(radioMultiply);
 radioMultiply.setBounds(10, 110, 74, 24);
 radioSubtract.setText("Subtract");
 groupOperator.add(radioSubtract);
 jPanel1.add(radioSubtract);
 radioSubtract.setBounds(10, 90, 74, 24);
 radioAdd.setSelected(true);
 radioAdd.setText("Add");
 groupOperator.add(radioAdd);
 jPanel1.add(radioAdd);
 radioAdd.setBounds(10, 70, 60, 24);
 editY.setForeground(new java.awt.Color(204, 0, 0));
 editY.setText("2");
 editY.setToolTipText("null");
 editY.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
editYActionPerformed(evt);
 }
 });
 jPanel1.add(editY);
 editY.setBounds(10, 40, 130, 20);
 editX.setForeground(new java.awt.Color(0, 51, 255));
 editX.setText("2");
 editX.setToolTipText("null");
 jPanel1.add(editX);
 editX.setBounds(10, 10, 130, 20);
 jLabel11.setText("First Number");
 jPanel1.add(jLabel11);
 jLabel11.setBounds(150, 10, 90, 16);
 jLabel1.setText("Second Number");
 jPanel1.add(jLabel1);
 jLabel1.setBounds(150, 40, 120, 16);
 buttonDoIt.setText("Math Method 2");
 buttonDoIt.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonDoItActionPerformed(evt);
 }
 });
 jPanel1.add(buttonDoIt);
 buttonDoIt.setBounds(110, 70, 130, 26);
 buttonDoIt2.setText("Do Dat' Math");
 buttonDoIt2.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonDoIt2ActionPerformed(evt);
 }
 });
 jPanel1.add(buttonDoIt2);
 buttonDoIt2.setBounds(110, 100, 130, 30);
 radioSqu.setText("Square");
 groupOperator.add(radioSqu);
 radioSqu.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
radioSquActionPerformed(evt);
 }
 });
 jPanel1.add(radioSqu);
 radioSqu.setBounds(10, 150, 66, 24);
 labelResult2.setForeground(new java.awt.Color(204, 0, 0));
 labelResult2.setText("Result 2");
 jPanel1.add(labelResult2);
 labelResult2.setBounds(140, 180, 110, 16);
 getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
 pack();
}
private void radioSquActionPerformed(java.awt.event.ActionEvent evt) {
 // Add your handling code here:
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
 setSize(270, 220);
 validate();
}
private void buttonDoIt2ActionPerformed(java.awt.event.ActionEvent evt) {
 // method 2
 if (radioAdd.isSelected())
 labelResult.setText(Double.toString(
Double.parseDouble(editX.getText()) + 
Double.parseDouble(editY.getText())
 ));
 else if (radioSubtract.isSelected())
 labelResult.setText(Double.toString(
Double.parseDouble(editX.getText()) -
Double.parseDouble(editY.getText())
 ));
 else if (radioMultiply.isSelected())
 labelResult.setText(Double.toString(
Double.parseDouble(editX.getText()) *
Double.parseDouble(editY.getText())
 ));
 else if (radioDivide.isSelected())
 labelResult.setText(Double.toString(
Double.parseDouble(editX.getText()) /
Double.parseDouble(editY.getText())
 ));
 else if (radioSqu.isSelected())
 labelResult.setText(Double.toString(
 Double.parseDouble(editX.getText()) *
 Double.parseDouble(editX.getText())
 ));
 labelResult2.setText(Double.toString(
 Double.parseDouble(editY.getText()) *
 Double.parseDouble(editY.getText())
 ));
}
private void editYActionPerformed(java.awt.event.ActionEvent evt) {
 // Add your handling code here:
}
private void buttonDoItActionPerformed(java.awt.event.ActionEvent evt) {
 // method 1
 double x = Double.parseDouble(editX.getText());
 double y = Double.parseDouble(editY.getText());
 
 // smack that math up
 double result = 0.0;
 double result2 = 0.0;
 
 if (radioAdd.isSelected())
 result = x + y;
 else if (radioSubtract.isSelected())
 result = x - y;
 else if (radioMultiply.isSelected())
 result = x * y;
 else if (radioDivide.isSelected())
 result = x / y;
 else if (radioSqu.isSelected()){
 result = x * x;
 result2 = y * y;
 }
 
 // show the result by changing our result number
 // back to a string and putting it in the label.
 labelResult.setText(Double.toString(result));
 labelResult2.setText(Double.toString(result2));
}
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
 System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
 new Chardonnay().show();
}
// Variables declaration - do not modify
private javax.swing.JRadioButton radioMultiply;
private javax.swing.JTextField editY;
private javax.swing.JLabel jLabel1;
private javax.swing.JTextField editX;
private javax.swing.JRadioButton radioSqu;
private javax.swing.JButton buttonDoIt2;
private javax.swing.JLabel labelResult;
private javax.swing.JRadioButton radioDivide;
private javax.swing.ButtonGroup groupOperator;
private javax.swing.JButton buttonDoIt;
private javax.swing.JRadioButton radioSubtract;
private javax.swing.JLabel jLabel11;
private javax.swing.JRadioButton radioAdd;
private javax.swing.JPanel jPanel1;
private javax.swing.JLabel labelResult2;
// End of variables declaration
}


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

11/17/2009 9:47:41 PMJohn Sun shinetocome

If you have code fileShare online,you could give me , please.
Thanks

(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.