Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package calcGui;
- public class GUI extends javax.swing.JFrame {
- double firstNumber;
- double secondNumber;
- String operation;
- /** Creates new form GUI */
- public GUI() {
- initComponents();
- }
- @SuppressWarnings("unchecked")
- "Generated Code spoiler thingy"
- private void btn1ActionPerformed(java.awt.event.ActionEvent evt) {
- String input = txtDisplay.getText() + btn1.getText();
- txtDisplay.setText(input);
- }
- private void btn2ActionPerformed(java.awt.event.ActionEvent evt) {
- String input = txtDisplay.getText() + btn2.getText();
- txtDisplay.setText(input);
- }
- private void btn3ActionPerformed(java.awt.event.ActionEvent evt) {
- String input = txtDisplay.getText() + btn3.getText();
- txtDisplay.setText(input);
- }
- private void btn4ActionPerformed(java.awt.event.ActionEvent evt) {
- String input = txtDisplay.getText() + btn4.getText();
- txtDisplay.setText(input);
- }
- private void btn5ActionPerformed(java.awt.event.ActionEvent evt) {
- String input = txtDisplay.getText() + btn5.getText();
- txtDisplay.setText(input);
- }
- private void btn6ActionPerformed(java.awt.event.ActionEvent evt) {
- String input = txtDisplay.getText() + btn6.getText();
- txtDisplay.setText(input);
- }
- private void btn7ActionPerformed(java.awt.event.ActionEvent evt) {
- String input = txtDisplay.getText() + btn7.getText();
- txtDisplay.setText(input);
- }
- private void btn8ActionPerformed(java.awt.event.ActionEvent evt) {
- String input = txtDisplay.getText() + btn8.getText();
- txtDisplay.setText(input);
- }
- private void btn9ActionPerformed(java.awt.event.ActionEvent evt) {
- String input = txtDisplay.getText() + btn9.getText();
- txtDisplay.setText(input);
- }
- private void btn0ActionPerformed(java.awt.event.ActionEvent evt) {
- String input = txtDisplay.getText() + btn0.getText();
- txtDisplay.setText(input);
- }
- private void btnClrActionPerformed(java.awt.event.ActionEvent evt) {
- txtDisplay.setText("");
- }
- private void btnPtActionPerformed(java.awt.event.ActionEvent evt) {
- int count = txtDisplay.getText().length() - txtDisplay.getText().replace(".", "").length();
- if(count == 0){
- String input= txtDisplay.getText() + btnPt.getText();
- txtDisplay.setText(input);
- }
- else{
- }
- }
- private void btnPlusActionPerformed(java.awt.event.ActionEvent evt) {
- firstNumber = Double.parseDouble(txtDisplay.getText());
- txtDisplay.setText("");
- operation = "+";
- }
- private void btnMnsActionPerformed(java.awt.event.ActionEvent evt) {
- firstNumber = Double.parseDouble(txtDisplay.getText());
- txtDisplay.setText("");
- operation = "-";
- }
- private void btnMultiActionPerformed(java.awt.event.ActionEvent evt) {
- firstNumber = Double.parseDouble(txtDisplay.getText());
- txtDisplay.setText("");
- operation = "*";
- }
- private void btnDivActionPerformed(java.awt.event.ActionEvent evt) {
- firstNumber = Double.parseDouble(txtDisplay.getText());
- txtDisplay.setText("");
- operation = "/";
- }
- private void btnEqActionPerformed(java.awt.event.ActionEvent evt) {
- secondNumber = Double.parseDouble(txtDisplay.getText());
- if ("+".equals(operation)) {
- double result = firstNumber + secondNumber;
- String answer = Double.toString(result);
- txtDisplay.setText(answer);
- }
- else if ("-".equals(operation)) {
- double result = firstNumber - secondNumber;
- String answer = Double.toString(result);
- txtDisplay.setText(answer);
- }
- else if ("*".equals(operation)) {
- double result = firstNumber * secondNumber;
- String answer = Double.toString(result);
- txtDisplay.setText(answer);
- }
- else {
- double result = firstNumber / secondNumber;
- String answer = Double.toString(result);
- txtDisplay.setText(answer);
- }
- }
- private void btnSignActionPerformed(java.awt.event.ActionEvent evt) {
- String number = txtDisplay.getText();
- double number1 = Double.parseDouble(number);
- number1 = number1 * (-1);
- txtDisplay.setText(String.valueOf(number1));
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- /* Create and display the form */
- "Look and feel spoiler thingy"
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new GUI().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton btn0;
- private javax.swing.JButton btn1;
- private javax.swing.JButton btn2;
- private javax.swing.JButton btn3;
- private javax.swing.JButton btn4;
- private javax.swing.JButton btn5;
- private javax.swing.JButton btn6;
- private javax.swing.JButton btn7;
- private javax.swing.JButton btn8;
- private javax.swing.JButton btn9;
- private javax.swing.JButton btnClr;
- private javax.swing.JButton btnDiv;
- private javax.swing.JButton btnEq;
- private javax.swing.JButton btnMns;
- private javax.swing.JButton btnMulti;
- private javax.swing.JButton btnPlus;
- private javax.swing.JButton btnPt;
- private javax.swing.JButton btnSign;
- private javax.swing.JTextField txtDisplay;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement