/* * ViewZor.java * * Created on 15 July 2007, 21:15 using NetBeans 5.5 IDE. * * CA 326 Third Year Project. * Bryan Carter - Student no: 53697673. * */ package calczor; import java.util.*; import java.lang.*; import java.math.*; /** * * @author Arquinsiel */ public class ViewZor extends javax.swing.JFrame { /** Creates new form ViewZor */ public ViewZor() { 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. */ Vector stuff = new Vector(); // a list to hold the entire calculation. Double answer; // the current state of the calculation. //int retControl = 1; // controls the execution of the calculation. Essentially a pointer to the next operation. //Integer operation = -1; // simply initialised to -1 for convenience sake, this tells the switch which case to select. Integer number = 0; // this represents the code of the operation type. Double tempDouble; boolean newCalc = true; // a signal to reset the calculator after a calculation is finished. boolean decBool = false; // a signal to say if a calculation already has a decimal point or not. // //GEN-BEGIN:initComponents private void initComponents() { CalculationField = new javax.swing.JTextField(); AnswerField = new javax.swing.JTextField(); NumPad = new javax.swing.JPanel(); Button7 = new javax.swing.JButton(); Button8 = new javax.swing.JButton(); Button9 = new javax.swing.JButton(); Button4 = new javax.swing.JButton(); Button5 = new javax.swing.JButton(); Button6 = new javax.swing.JButton(); Button1 = new javax.swing.JButton(); Button2 = new javax.swing.JButton(); Button3 = new javax.swing.JButton(); Button0 = new javax.swing.JButton(); ButtonDec = new javax.swing.JButton(); ButtonTab = new javax.swing.JButton(); OperatorPanel = new javax.swing.JPanel(); AddButton = new javax.swing.JButton(); SubButton = new javax.swing.JButton(); MulButton = new javax.swing.JButton(); DivButton = new javax.swing.JButton(); RootButton = new javax.swing.JButton(); ModBUtton = new javax.swing.JButton(); RecButton = new javax.swing.JButton(); IndexButton = new javax.swing.JButton(); EditPanel = new javax.swing.JPanel(); ClearButton = new javax.swing.JButton(); DelButton = new javax.swing.JButton(); RetButton = new javax.swing.JButton(); MenuBar = new javax.swing.JMenuBar(); EditMenu = new javax.swing.JMenu(); ExitButton = new javax.swing.JMenuItem(); ViewMenu = new javax.swing.JMenu(); Standard = new javax.swing.JRadioButtonMenuItem(); Scientific = new javax.swing.JRadioButtonMenuItem(); jSeparator1 = new javax.swing.JSeparator(); AboutMenu = new javax.swing.JMenu(); AboutButton = new javax.swing.JMenuItem(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("CA 326 - Calculator "); CalculationField.setHorizontalAlignment(javax.swing.JTextField.TRAILING); AnswerField.setHorizontalAlignment(javax.swing.JTextField.TRAILING); AnswerField.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { AnswerFieldActionPerformed(evt); } }); Button7.setText("7"); Button7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { Button7ActionPerformed(evt); } }); Button7.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { Button7KeyTyped(evt); } }); Button8.setText("8"); Button8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { Button8ActionPerformed(evt); } }); Button8.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { Button8KeyTyped(evt); } }); Button9.setText("9"); Button9.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { Button9ActionPerformed(evt); } }); Button9.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { Button9KeyTyped(evt); } }); Button4.setText("4"); Button4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { Button4ActionPerformed(evt); } }); Button4.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { Button4KeyTyped(evt); } }); Button5.setText("5"); Button5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { Button5ActionPerformed(evt); } }); Button5.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { Button5KeyTyped(evt); } }); Button6.setText("6"); Button6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { Button6ActionPerformed(evt); } }); Button6.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { Button6KeyTyped(evt); } }); Button1.setText("1"); Button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { Button1ActionPerformed(evt); } }); Button1.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { Button1KeyTyped(evt); } }); Button2.setText("2"); Button2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { Button2ActionPerformed(evt); } }); Button2.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { Button2KeyTyped(evt); } }); Button3.setText("3"); Button3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { Button3ActionPerformed(evt); } }); Button3.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { Button3KeyTyped(evt); } }); Button0.setText("0"); Button0.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { Button0ActionPerformed(evt); } }); Button0.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { Button0KeyTyped(evt); } }); ButtonDec.setText("."); ButtonDec.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ButtonDecActionPerformed(evt); } }); ButtonTab.setText("+/-"); ButtonTab.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ButtonTabActionPerformed(evt); } }); javax.swing.GroupLayout NumPadLayout = new javax.swing.GroupLayout(NumPad); NumPad.setLayout(NumPadLayout); NumPadLayout.setHorizontalGroup( NumPadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(NumPadLayout.createSequentialGroup() .addGroup(NumPadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(NumPadLayout.createSequentialGroup() .addComponent(Button0) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(ButtonDec) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(ButtonTab)) .addGroup(NumPadLayout.createSequentialGroup() .addGroup(NumPadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(Button4, 0, 0, Short.MAX_VALUE) .addComponent(Button7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(NumPadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(Button5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(Button8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(NumPadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(Button6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(Button9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addGroup(NumPadLayout.createSequentialGroup() .addComponent(Button1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(Button2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(Button3))) .addContainerGap()) ); NumPadLayout.setVerticalGroup( NumPadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(NumPadLayout.createSequentialGroup() .addGroup(NumPadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Button7) .addComponent(Button8) .addComponent(Button9)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(NumPadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Button4) .addComponent(Button5) .addComponent(Button6)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(NumPadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Button1) .addComponent(Button2) .addComponent(Button3)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(NumPadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Button0) .addComponent(ButtonDec) .addComponent(ButtonTab)) .addContainerGap()) ); AddButton.setText("+"); AddButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { AddButtonActionPerformed(evt); } }); AddButton.getAccessibleContext().setAccessibleName("PlusButton"); SubButton.setText("-"); SubButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { SubButtonActionPerformed(evt); } }); SubButton.getAccessibleContext().setAccessibleName("MinusButton"); MulButton.setText("*"); MulButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { MulButtonActionPerformed(evt); } }); MulButton.getAccessibleContext().setAccessibleName("MulButton"); DivButton.setText("/"); DivButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { DivButtonActionPerformed(evt); } }); DivButton.getAccessibleContext().setAccessibleName("DivButton"); RootButton.setText("Sqrt"); RootButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { RootButtonActionPerformed(evt); } }); RootButton.getAccessibleContext().setAccessibleName("RootButton"); ModBUtton.setText("%"); ModBUtton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ModBUttonActionPerformed(evt); } }); ModBUtton.getAccessibleContext().setAccessibleName("ModButton"); RecButton.setText("1/x"); RecButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { RecButtonActionPerformed(evt); } }); RecButton.getAccessibleContext().setAccessibleName("RecipButton"); IndexButton.setText("n^x"); IndexButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { IndexButtonActionPerformed(evt); } }); javax.swing.GroupLayout OperatorPanelLayout = new javax.swing.GroupLayout(OperatorPanel); OperatorPanel.setLayout(OperatorPanelLayout); OperatorPanelLayout.setHorizontalGroup( OperatorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(OperatorPanelLayout.createSequentialGroup() .addGroup(OperatorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(DivButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(MulButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(SubButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(AddButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(2, 2, 2) .addGroup(OperatorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(ModBUtton, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE) .addComponent(RootButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE) .addComponent(RecButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE) .addComponent(IndexButton, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE))) ); OperatorPanelLayout.setVerticalGroup( OperatorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(OperatorPanelLayout.createSequentialGroup() .addGroup(OperatorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(AddButton) .addComponent(RootButton)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(OperatorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(SubButton) .addComponent(ModBUtton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(OperatorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(MulButton) .addComponent(RecButton)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(OperatorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(IndexButton) .addComponent(DivButton)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); ClearButton.setText("CE"); ClearButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ClearButtonActionPerformed(evt); } }); ClearButton.getAccessibleContext().setAccessibleName("CEButton"); DelButton.setText("Delete"); DelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { DelButtonActionPerformed(evt); } }); DelButton.getAccessibleContext().setAccessibleName("DeleteButton"); RetButton.setText("Answer"); RetButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { RetButtonActionPerformed(evt); } }); RetButton.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { RetButtonKeyTyped(evt); } }); RetButton.getAccessibleContext().setAccessibleName("AnswerButton"); javax.swing.GroupLayout EditPanelLayout = new javax.swing.GroupLayout(EditPanel); EditPanel.setLayout(EditPanelLayout); EditPanelLayout.setHorizontalGroup( EditPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(ClearButton, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE) .addComponent(DelButton, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE) .addComponent(RetButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); EditPanelLayout.setVerticalGroup( EditPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(EditPanelLayout.createSequentialGroup() .addComponent(DelButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(ClearButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(RetButton, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); EditMenu.setText("Edit"); ExitButton.setText("Exit"); ExitButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ExitButtonActionPerformed(evt); } }); EditMenu.add(ExitButton); MenuBar.add(EditMenu); ViewMenu.setText("Menu"); Standard.setSelected(true); Standard.setText("Standard"); ViewMenu.add(Standard); Scientific.setText("Scientific"); ViewMenu.add(Scientific); ViewMenu.add(jSeparator1); MenuBar.add(ViewMenu); AboutMenu.setText("About"); AboutButton.setText("About"); AboutButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { AboutButtonActionPerformed(evt); } }); AboutMenu.add(AboutButton); MenuBar.add(AboutMenu); setJMenuBar(MenuBar); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(AnswerField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 318, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addComponent(NumPad, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(OperatorPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(EditPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(CalculationField, javax.swing.GroupLayout.DEFAULT_SIZE, 318, Short.MAX_VALUE)) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(CalculationField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(AnswerField, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(OperatorPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(NumPad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(EditPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap()) ); pack(); }// //GEN-END:initComponents private int factorial(int FactInt) // a recursive method to find factorials of ints. later requires re-conversion to Double. Not used in final version. { if (FactInt == 1) { return FactInt; }else { int tempInt = FactInt * factorial(FactInt - 1); return tempInt; } } private Double squareRoot(Double number) // a method to take the Double and return the Square Root. { Double finalNumber = Math.sqrt(number); return finalNumber; } private Double reciprocal(Double most, Double Numerator, Double Denominator) // a method to convert a reciprocal fraction into a decimal. { Double temp = Numerator/Denominator; answer = most + temp; return answer; } private Double powers(Double num, Double power) // a recursive method to do indices. { Double answer = 1.0; if (power == 0) { return answer; }else if(power == 1) { return num; }else { return num * powers(num, power-1); } } private void RetButtonKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_RetButtonKeyTyped // TODO add your handling code here: }//GEN-LAST:event_RetButtonKeyTyped private void Button9KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_Button9KeyTyped // TODO add your handling code here: }//GEN-LAST:event_Button9KeyTyped private void Button8KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_Button8KeyTyped // TODO add your handling code here: }//GEN-LAST:event_Button8KeyTyped private void Button7KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_Button7KeyTyped // TODO add your handling code here: }//GEN-LAST:event_Button7KeyTyped private void Button6KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_Button6KeyTyped // TODO add your handling code here: }//GEN-LAST:event_Button6KeyTyped private void Button5KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_Button5KeyTyped // TODO add your handling code here: }//GEN-LAST:event_Button5KeyTyped private void Button4KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_Button4KeyTyped // TODO add your handling code here: }//GEN-LAST:event_Button4KeyTyped private void Button3KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_Button3KeyTyped // TODO add your handling code here: }//GEN-LAST:event_Button3KeyTyped private void Button2KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_Button2KeyTyped // TODO add your handling code here: }//GEN-LAST:event_Button2KeyTyped private void Button1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_Button1KeyTyped // TODO add your handling code here: }//GEN-LAST:event_Button1KeyTyped private void Button0KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_Button0KeyTyped // If the box is empty do nothing, otherwise add a zero to the end of the string. //Button8ActionPerformed(java.awt.event.ActionEvent evt); /*String AnswerText = AnswerField.getText(); if (AnswerText != null) { AnswerText = AnswerText + "0"; AnswerField.setText(AnswerText); }*/ }//GEN-LAST:event_Button0KeyTyped private void IndexButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_IndexButtonActionPerformed // Adds the current number to the vector and the code for the operation. String AnswerText = AnswerField.getText(); String tempString = CalculationField.getText(); stuff.add(AnswerText); CalculationField.setText(tempString + AnswerText + " ^ "); number = 8; stuff.add(number); AnswerField.setText(null); decBool = false; }//GEN-LAST:event_IndexButtonActionPerformed private void RecButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RecButtonActionPerformed // TODO add your handling code here: String AnswerText = AnswerField.getText(); String tempString = CalculationField.getText(); stuff.add(AnswerText); CalculationField.setText(tempString + AnswerText + "/"); number = 7; stuff.add(number); AnswerField.setText(null); }//GEN-LAST:event_RecButtonActionPerformed private void ModBUttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ModBUttonActionPerformed // Adds the current number to the vector and the code for the operation. String AnswerText = AnswerField.getText(); String tempString = CalculationField.getText(); stuff.add(AnswerText); CalculationField.setText(tempString + AnswerText + " % "); number = 6; stuff.add(number); AnswerField.setText(null); }//GEN-LAST:event_ModBUttonActionPerformed private void RootButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RootButtonActionPerformed // Adds the current number to the vector and the code for the operation. String AnswerText = AnswerField.getText(); String tempString = CalculationField.getText(); stuff.add(null); number = 5; stuff.add(number); tempString = "root "; // U+221A.toString(); //AnswerText = tempString + AnswerText; AnswerText = tempString; CalculationField.setText(tempString); decBool = false; }//GEN-LAST:event_RootButtonActionPerformed private void ClearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClearButtonActionPerformed // Clears the current item. String AnswerText = AnswerField.getText(); AnswerText = null; AnswerField.setText(AnswerText); decBool = false; }//GEN-LAST:event_ClearButtonActionPerformed private void DelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DelButtonActionPerformed // deletes the last character entered. String AnswerText = AnswerField.getText(); AnswerText = AnswerText.substring(0,AnswerText.length()-1); AnswerField.setText(AnswerText); }//GEN-LAST:event_DelButtonActionPerformed private void AboutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AboutButtonActionPerformed // should create a new form which opens the about box in a window. AboutBox Box = new AboutBox(); Box.setVisible(true); }//GEN-LAST:event_AboutButtonActionPerformed private void ExitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExitButtonActionPerformed // kills the program upon clicking the menuitem. dispose(); System.exit(0); }//GEN-LAST:event_ExitButtonActionPerformed private void DivButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DivButtonActionPerformed // Adds the current number to the vector and the code for the operation. String AnswerText = AnswerField.getText(); String tempString = CalculationField.getText(); stuff.add(AnswerText); CalculationField.setText(tempString + AnswerText + " / "); number = 4; stuff.add(number); decBool = false; AnswerField.setText(null); }//GEN-LAST:event_DivButtonActionPerformed private void MulButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MulButtonActionPerformed // Adds the current number to the vector and the code for the operation. String AnswerText = AnswerField.getText(); String tempString = CalculationField.getText(); stuff.add(AnswerText); CalculationField.setText(tempString + AnswerText + " * "); number = 3; stuff.add(number); decBool = false; AnswerField.setText(null); }//GEN-LAST:event_MulButtonActionPerformed private void SubButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SubButtonActionPerformed // Adds the current number to the vector and the code for the operation. String AnswerText = AnswerField.getText(); String tempString = CalculationField.getText(); stuff.add(AnswerText); CalculationField.setText(tempString + AnswerText + " - "); number = 2; stuff.add(number); decBool = false; AnswerField.setText(null); }//GEN-LAST:event_SubButtonActionPerformed private void AddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddButtonActionPerformed // Adds the current number to the vector and the code for the operation. String AnswerText = AnswerField.getText(); String tempString = CalculationField.getText(); stuff.add(AnswerText); CalculationField.setText(tempString + AnswerText + " + "); number = 1; stuff.add(number); decBool = false; AnswerField.setText(null); }//GEN-LAST:event_AddButtonActionPerformed private void RetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RetButtonActionPerformed // While the vector still has elements to it run through it and perform the operation. int retControl = 1; // moves onto the first operation, later used as a pointer to the operation code. String AnswerText = AnswerField.getText(); // takes the current (and last) item entered. stuff.add(AnswerText); // adds it to the vector for later retrieval. String tempString = CalculationField.getText(); // takes the entire calculation from the relevant field. CalculationField.setText(tempString + AnswerText); // adds the last item to above and displays the entire calculation. String startString = stuff.elementAt(0).toString(); // takes the first item from the vector and answer = Double.parseDouble(startString); // converts it to something usable. while (retControl < stuff.size()-1) // while we have information in the vector, keep stepping through until it has all been processed. { tempString = stuff.elementAt(retControl).toString(); // retrieves the operation code and int operation = Integer.parseInt(tempString); // converts it to an integer tempString = stuff.elementAt(retControl+1).toString(); // retrieves the item ahead of the operation counter. tempDouble = Double.parseDouble(tempString); // makes it usable. switch (operation) // switches to cases based on operation code, different case for each operation. { case 1: answer = answer + tempDouble; break; // addition case 2: answer = answer - tempDouble; break; // subtraction case 3: answer = answer * tempDouble; break; // multiplication case 4: answer = answer / tempDouble; break; // division case 5: answer = squareRoot(tempDouble); // roots case 6: answer = answer % tempDouble; break; // modulus case 7: String tempDenominator = stuff.elementAt(retControl+3).toString(); Double denominator = Double.parseDouble(tempDenominator); answer = reciprocal(answer, tempDouble, denominator); break; case 8: answer = powers(answer, tempDouble); break; // indices /* Failed cases for doing Sin, Cos, Tan and Factorials. case 9: answer = Math.sin(tempDouble); break; // sin case 10: answer = Math.cos(tempDouble); break; // cos case 11: answer = Math.tan(tempDouble); break; // tan case 12: Integer FactInt = Integer.parseInt(AnswerText); FactInt = factorial(FactInt); tempString = FactInt.toString(); answer = Double.parseDouble(tempString); break; // factorial */ } retControl = retControl + 2; // jump ahead two vector items. } AnswerField.setText(answer.toString()); // outputs the final answer to the answerfield. newCalc = false; decBool = false; stuff = new Vector(); }//GEN-LAST:event_RetButtonActionPerformed private void ButtonTabActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonTabActionPerformed // TODO add your handling code here: if (newCalc == false) { CalculationField.setText(null); AnswerField.setText(null); } String AnswerText = AnswerField.getText(); // get the current number. if (AnswerText.substring(0,1).equals("-") == false) // if it doesn't have a "-" at the start { AnswerText = "-" + AnswerText; // put one there. }else if(AnswerText.substring(0,1).equals("-")) // of if it does { AnswerText = AnswerText.substring(1,AnswerText.length());// take it away. } AnswerField.setText(AnswerText); // then send it back. }//GEN-LAST:event_ButtonTabActionPerformed private void ButtonDecActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonDecActionPerformed // TODO add your handling code here: if (decBool == false) { if (newCalc == false) { CalculationField.setText(""); AnswerField.setText(""); } String AnswerText = AnswerField.getText(); // check the number. if (AnswerText == null) // if it's blank { AnswerText = "0."; // add "0." AnswerField.setText(AnswerText); // and return it. }else // if there is a number there. { AnswerText = AnswerText + "."; // simply add a "." to it. AnswerField.setText(AnswerText); // then send it back. } decBool = true; }else { } }//GEN-LAST:event_ButtonDecActionPerformed private void Button0ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Button0ActionPerformed // If the box is empty do nothing, otherwise add a zero to the end of the string. if (newCalc == false) { CalculationField.setText(""); AnswerField.setText(""); } String AnswerText = AnswerField.getText(); if (AnswerText != null) { AnswerText = AnswerText + "0"; AnswerField.setText(AnswerText); } }//GEN-LAST:event_Button0ActionPerformed private void Button3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Button3ActionPerformed // TODO add your handling code here: if (newCalc == false) { CalculationField.setText(""); AnswerField.setText(""); } String AnswerText = AnswerField.getText(); if (AnswerText == null) { AnswerText = "3"; AnswerField.setText(AnswerText); }else { AnswerText = AnswerText + "3"; AnswerField.setText(AnswerText); } }//GEN-LAST:event_Button3ActionPerformed private void Button2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Button2ActionPerformed // TODO add your handling code here: if (newCalc == false) { CalculationField.setText(""); AnswerField.setText(""); } String AnswerText = AnswerField.getText(); if (AnswerText == null) { AnswerText = "2"; AnswerField.setText(AnswerText); }else { AnswerText = AnswerText + "2"; AnswerField.setText(AnswerText); } }//GEN-LAST:event_Button2ActionPerformed private void Button1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Button1ActionPerformed // TODO add your handling code here: String AnswerText = AnswerField.getText(); if (AnswerText == null) { AnswerText = "1"; AnswerField.setText(AnswerText); }else { AnswerText = AnswerText + "1"; AnswerField.setText(AnswerText); } }//GEN-LAST:event_Button1ActionPerformed private void Button6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Button6ActionPerformed // TODO add your handling code here: if (newCalc == false) { CalculationField.setText(""); AnswerField.setText(""); } String AnswerText = AnswerField.getText(); if (AnswerText == null) { AnswerText = "6"; AnswerField.setText(AnswerText); }else { AnswerText = AnswerText + "6"; AnswerField.setText(AnswerText); } }//GEN-LAST:event_Button6ActionPerformed private void Button5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Button5ActionPerformed // TODO add your handling code here: if (newCalc == false) { CalculationField.setText(""); AnswerField.setText(""); } String AnswerText = AnswerField.getText(); if (AnswerText == null) { AnswerText = "5"; AnswerField.setText(AnswerText); }else { AnswerText = AnswerText + "5"; AnswerField.setText(AnswerText); } }//GEN-LAST:event_Button5ActionPerformed private void Button4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Button4ActionPerformed // TODO add your handling code here: if (newCalc == false) { CalculationField.setText(""); AnswerField.setText(""); } String AnswerText = AnswerField.getText(); if (AnswerText == null) { AnswerText = "4"; AnswerField.setText(AnswerText); }else { AnswerText = AnswerText + "4"; AnswerField.setText(AnswerText); } }//GEN-LAST:event_Button4ActionPerformed private void Button9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Button9ActionPerformed // TODO add your handling code here: if (newCalc == false) { CalculationField.setText(""); AnswerField.setText(""); } String AnswerText = AnswerField.getText(); if (AnswerText == null) { AnswerText = "9"; AnswerField.setText(AnswerText); }else { AnswerText = AnswerText + "9"; AnswerField.setText(AnswerText); } }//GEN-LAST:event_Button9ActionPerformed private void Button8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Button8ActionPerformed // TODO add your handling code here: if (newCalc == false) { CalculationField.setText(""); AnswerField.setText(""); } String AnswerText = AnswerField.getText(); if (AnswerText == null) { AnswerText = "8"; AnswerField.setText(AnswerText); }else { AnswerText = AnswerText + "8"; AnswerField.setText(AnswerText); } }//GEN-LAST:event_Button8ActionPerformed private void AnswerFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AnswerFieldActionPerformed // TODO add your handling code here: }//GEN-LAST:event_AnswerFieldActionPerformed private void Button7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Button7ActionPerformed // TODO add your handling code here: if (newCalc == false) { CalculationField.setText(""); AnswerField.setText(""); } String AnswerText = AnswerField.getText(); if (AnswerText == null) { AnswerText = "7"; AnswerField.setText(AnswerText); }else { AnswerText = AnswerText + "7"; AnswerField.setText(AnswerText); } }//GEN-LAST:event_Button7ActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new ViewZor().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JMenuItem AboutButton; private javax.swing.JMenu AboutMenu; private javax.swing.JButton AddButton; private javax.swing.JTextField AnswerField; private javax.swing.JButton Button0; private javax.swing.JButton Button1; private javax.swing.JButton Button2; private javax.swing.JButton Button3; private javax.swing.JButton Button4; private javax.swing.JButton Button5; private javax.swing.JButton Button6; private javax.swing.JButton Button7; private javax.swing.JButton Button8; private javax.swing.JButton Button9; private javax.swing.JButton ButtonDec; private javax.swing.JButton ButtonTab; private javax.swing.JTextField CalculationField; private javax.swing.JButton ClearButton; private javax.swing.JButton DelButton; private javax.swing.JButton DivButton; private javax.swing.JMenu EditMenu; private javax.swing.JPanel EditPanel; private javax.swing.JMenuItem ExitButton; private javax.swing.JButton IndexButton; private javax.swing.JMenuBar MenuBar; private javax.swing.JButton ModBUtton; private javax.swing.JButton MulButton; private javax.swing.JPanel NumPad; private javax.swing.JPanel OperatorPanel; private javax.swing.JButton RecButton; private javax.swing.JButton RetButton; private javax.swing.JButton RootButton; private javax.swing.JRadioButtonMenuItem Scientific; private javax.swing.JRadioButtonMenuItem Standard; private javax.swing.JButton SubButton; private javax.swing.JMenu ViewMenu; private javax.swing.JSeparator jSeparator1; // End of variables declaration//GEN-END:variables //AnswerText = AnswerField.getText(); //Double Answer = AnswerText.toDouble(); }