Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- public class Calc {
- public static void main(String[] args) {
- try {
- String systemLookAndFeelClassName = UIManager.getSystemLookAndFeelClassName();
- UIManager.setLookAndFeel(systemLookAndFeelClassName);
- } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
- }
- java.awt.EventQueue.invokeLater(() -> {
- Gui gui = new Gui();
- gui.setLocationRelativeTo(null);
- gui.setVisible(true);
- });
- }
- }
- public class Gui extends javax.swing.JFrame {
- double firstNum = 0;
- String operation = "";
- public Gui() {
- initComponents();
- }
- //@SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jTextField1 = new javax.swing.JTextField();
- jButton1 = new javax.swing.JButton();
- jButton5 = new javax.swing.JButton();
- jButton6 = new javax.swing.JButton();
- jButton7 = new javax.swing.JButton();
- jButton8 = new javax.swing.JButton();
- jButton9 = new javax.swing.JButton();
- jButton10 = new javax.swing.JButton();
- jButton11 = new javax.swing.JButton();
- jButton12 = new javax.swing.JButton();
- jButton13 = new javax.swing.JButton();
- jButton14 = new javax.swing.JButton();
- jButton15 = new javax.swing.JButton();
- jButton16 = new javax.swing.JButton();
- jButton17 = new javax.swing.JButton();
- jButton18 = new javax.swing.JButton();
- jButton19 = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setTitle("Calculator v1.0");
- setBackground(new java.awt.Color(204, 204, 204));
- setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
- setForeground(new java.awt.Color(255, 255, 255));
- setResizable(false);
- jTextField1.setFont(new java.awt.Font("Arial", 0, 24)); // NOI18N
- jTextField1.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
- jTextField1.setToolTipText("");
- jTextField1.setEnabled(false);
- jTextField1.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- jTextField1MouseClicked(evt);
- }
- });
- jButton1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jButton1.setText("7");
- jButton1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
- jButton1.setFocusPainted(false);
- jButton1.setFocusable(false);
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jButton5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jButton5.setText("4");
- jButton5.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
- jButton5.setFocusPainted(false);
- jButton5.setFocusable(false);
- jButton5.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton5ActionPerformed(evt);
- }
- });
- jButton6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jButton6.setText("1");
- jButton6.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
- jButton6.setFocusPainted(false);
- jButton6.setFocusable(false);
- jButton6.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton6ActionPerformed(evt);
- }
- });
- jButton7.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jButton7.setText("2");
- jButton7.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
- jButton7.setFocusPainted(false);
- jButton7.setFocusable(false);
- jButton7.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton7ActionPerformed(evt);
- }
- });
- jButton8.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jButton8.setText("8");
- jButton8.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
- jButton8.setFocusPainted(false);
- jButton8.setFocusable(false);
- jButton8.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton8ActionPerformed(evt);
- }
- });
- jButton9.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jButton9.setText("9");
- jButton9.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
- jButton9.setFocusPainted(false);
- jButton9.setFocusable(false);
- jButton9.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton9ActionPerformed(evt);
- }
- });
- jButton10.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jButton10.setText("/");
- jButton10.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
- jButton10.setFocusPainted(false);
- jButton10.setFocusable(false);
- jButton10.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton10ActionPerformed(evt);
- }
- });
- jButton11.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jButton11.setText("5");
- jButton11.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
- jButton11.setFocusPainted(false);
- jButton11.setFocusable(false);
- jButton11.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton11ActionPerformed(evt);
- }
- });
- jButton12.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jButton12.setText("6");
- jButton12.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
- jButton12.setFocusPainted(false);
- jButton12.setFocusable(false);
- jButton12.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton12ActionPerformed(evt);
- }
- });
- jButton13.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jButton13.setText("*");
- jButton13.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
- jButton13.setFocusPainted(false);
- jButton13.setFocusable(false);
- jButton13.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton13ActionPerformed(evt);
- }
- });
- jButton14.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jButton14.setText("3");
- jButton14.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
- jButton14.setFocusPainted(false);
- jButton14.setFocusable(false);
- jButton14.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton14ActionPerformed(evt);
- }
- });
- jButton15.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jButton15.setText("+");
- jButton15.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
- jButton15.setFocusPainted(false);
- jButton15.setFocusable(false);
- jButton15.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton15ActionPerformed(evt);
- }
- });
- jButton16.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jButton16.setText("0");
- jButton16.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
- jButton16.setFocusPainted(false);
- jButton16.setFocusable(false);
- jButton16.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton16ActionPerformed(evt);
- }
- });
- jButton17.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jButton17.setText(".");
- jButton17.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
- jButton17.setFocusPainted(false);
- jButton17.setFocusable(false);
- jButton17.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton17ActionPerformed(evt);
- }
- });
- jButton18.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jButton18.setText("=");
- jButton18.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
- jButton18.setFocusPainted(false);
- jButton18.setFocusable(false);
- jButton18.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton18ActionPerformed(evt);
- }
- });
- jButton19.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jButton19.setText("-");
- jButton19.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
- jButton19.setFocusPainted(false);
- jButton19.setFocusable(false);
- jButton19.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton19ActionPerformed(evt);
- }
- });
- 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(jTextField1)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton10, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton12, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton13, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addGap(6, 6, 6)
- .addComponent(jButton14, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton15, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jButton16, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton17, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton18, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton19, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addGap(0, 0, Short.MAX_VALUE)))
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton10, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton13, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton12, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton15, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton14, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton16, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton17, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton18, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton19, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- jTextField1.setText(jTextField1.getText() + "7");
- }
- private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {
- jTextField1.setText(jTextField1.getText() + "8");
- }
- private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {
- jTextField1.setText(jTextField1.getText() + "9");
- }
- private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {
- jTextField1.setText(jTextField1.getText() + "0");
- }
- private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
- jTextField1.setText(jTextField1.getText() + "1");
- }
- private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
- jTextField1.setText(jTextField1.getText() + "2");
- }
- private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {
- jTextField1.setText(jTextField1.getText() + "3");
- }
- private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
- jTextField1.setText(jTextField1.getText() + "4");
- }
- private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {
- jTextField1.setText(jTextField1.getText() + "5");
- }
- private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {
- jTextField1.setText(jTextField1.getText() + "6");
- }
- private void jTextField1MouseClicked(java.awt.event.MouseEvent evt) {
- String temp = jTextField1.getText();
- int len = 0;
- if(len != temp.length()) {
- jTextField1.setText(temp.substring(0, temp.length() - 1).trim());
- }
- }
- private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {
- firstNum = Double.valueOf(jTextField1.getText());
- operation = " / ";
- String temp = String.valueOf(firstNum);
- if(temp.endsWith(".0")) {
- temp = temp.substring(0, temp.length() - 2);
- jTextField1.setText(temp + operation);
- } else {
- jTextField1.setText(temp + operation);
- }
- }
- private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {
- firstNum = Double.valueOf(jTextField1.getText());
- operation = " * ";
- String temp = String.valueOf(firstNum);
- if(temp.endsWith(".0")) {
- temp = temp.substring(0, temp.length() - 2);
- jTextField1.setText(temp + operation);
- } else {
- jTextField1.setText(temp + operation);
- }
- }
- private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {
- firstNum = Double.valueOf(jTextField1.getText());
- operation = " + ";
- String temp = String.valueOf(firstNum);
- if(temp.endsWith(".0")) {
- temp = temp.substring(0, temp.length() - 2);
- jTextField1.setText(temp + operation);
- } else {
- jTextField1.setText(temp + operation);
- }
- }
- private void jButton19ActionPerformed(java.awt.event.ActionEvent evt) {
- firstNum = Double.valueOf(jTextField1.getText());
- operation = " - ";
- String temp = String.valueOf(firstNum);
- if(temp.endsWith(".0")) {
- temp = temp.substring(0, temp.length() - 2);
- jTextField1.setText(temp + operation);
- } else {
- jTextField1.setText(temp + operation);
- }
- }
- private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) {
- String temp = jTextField1.getText();
- boolean flag = true;
- int a = temp.indexOf("*");
- int b = temp.indexOf("/");
- int c = temp.indexOf("-");
- int d = temp.indexOf("+");
- double secondNum;
- if(operation.trim().equals("*")) {
- secondNum = Double.valueOf(temp.substring(a + 2));
- double p1 = firstNum * secondNum;
- p1 = new BigDecimal(p1).setScale(14, RoundingMode.HALF_UP).doubleValue();
- temp = String.valueOf(p1);
- if (temp.endsWith(".0")) {
- temp = String.valueOf(p1).substring(0, String.valueOf(p1).length() - 2);
- } else {
- temp = String.valueOf(p1).substring(0, String.valueOf(p1).length());
- }
- jTextField1.setText(temp);
- } else if (operation.trim().equals("/")) {
- secondNum = Double.valueOf(temp.substring(b + 2));
- double p2 = firstNum / secondNum;
- temp = String.valueOf(p2);
- /* if(!temp.equals("Infinite") | !temp.equals("NaN")) {
- p2 = new BigDecimal(p2).setScale(10, RoundingMode.HALF_UP).doubleValue();
- }*/
- if (temp.endsWith(".0")) {
- temp = String.valueOf(p2).substring(0, String.valueOf(p2).length() - 2);
- } else {
- temp = String.valueOf(p2).substring(0, String.valueOf(p2).length());
- }
- jTextField1.setText(temp);
- } else if (operation.trim().equals("-")) {
- secondNum = Double.valueOf(temp.substring(c + 2));
- double p3 = firstNum - secondNum;
- p3 = new BigDecimal(p3).setScale(14, RoundingMode.HALF_UP).doubleValue();
- temp = String.valueOf(p3);
- if (temp.endsWith(".0")) {
- temp = String.valueOf(p3).substring(0, String.valueOf(p3).length() - 2);
- } else {
- temp = String.valueOf(p3).substring(0, String.valueOf(p3).length());
- }
- jTextField1.setText(temp);
- } else if (operation.trim().equals("+")) {
- secondNum = Double.valueOf(temp.substring(d + 2));
- double p4 = firstNum + secondNum;
- p4 = new BigDecimal(p4).setScale(14, RoundingMode.HALF_UP).doubleValue();
- temp = String.valueOf(p4);
- if (temp.endsWith(".0")) {
- temp = String.valueOf(p4).substring(0, String.valueOf(p4).length() - 2);
- } else {
- temp = String.valueOf(p4).substring(0, String.valueOf(p4).length());
- }
- jTextField1.setText(temp);
- }
- }
- private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) {
- jTextField1.setText(jTextField1.getText() + ".");
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton10;
- private javax.swing.JButton jButton11;
- private javax.swing.JButton jButton12;
- private javax.swing.JButton jButton13;
- private javax.swing.JButton jButton14;
- private javax.swing.JButton jButton15;
- private javax.swing.JButton jButton16;
- private javax.swing.JButton jButton17;
- private javax.swing.JButton jButton18;
- private javax.swing.JButton jButton19;
- private javax.swing.JButton jButton5;
- private javax.swing.JButton jButton6;
- private javax.swing.JButton jButton7;
- private javax.swing.JButton jButton8;
- private javax.swing.JButton jButton9;
- private javax.swing.JTextField jTextField1;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement