Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package calculator;
- import java.util.Stack;
- import javax.swing.JButton;
- /**
- *
- * @author bas
- */
- public class GrafOb extends javax.swing.JFrame {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- /**
- * Creates new form GrafOb
- */
- public GrafOb() {
- initComponents();
- jPanel3.setVisible(false);
- }
- private void initComponents() {
- jPanel1 = new javax.swing.JPanel();
- jTextField1 = new javax.swing.JTextField();
- jButtonPlusMin = new javax.swing.JButton();
- jButtonC = new javax.swing.JButton();
- jButtonRound = new javax.swing.JButton();
- jButtonExit = new javax.swing.JButton();
- jButtonPlus = new javax.swing.JButton();
- jButtonSqrt = new javax.swing.JButton();
- jButtonQuadr = new javax.swing.JButton();
- jButtonMin = new javax.swing.JButton();
- jButton7 = new javax.swing.JButton();
- jButton8 = new javax.swing.JButton();
- jButton9 = new javax.swing.JButton();
- jButtonMult = new javax.swing.JButton();
- jButtonDiv = new javax.swing.JButton();
- jButton4 = new javax.swing.JButton();
- jButton5 = new javax.swing.JButton();
- jButtonMod = new javax.swing.JButton();
- jButton1getX = new javax.swing.JButton();
- jButton6 = new javax.swing.JButton();
- jButton1 = new javax.swing.JButton();
- jButtonDot = new javax.swing.JButton();
- jButton3 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- jButtonEquals = new javax.swing.JButton();
- jButton0 = new javax.swing.JButton();
- jTextFieldNachkst = new javax.swing.JTextField();
- jLabel1 = new javax.swing.JLabel();
- jPanel3 = new javax.swing.JPanel();
- jLabel6 = new javax.swing.JLabel();
- jLabel7 = new javax.swing.JLabel();
- jLabel8 = new javax.swing.JLabel();
- jButtonConvert = new javax.swing.JButton();
- jLabel9 = new javax.swing.JLabel();
- jTextFieldNumToConv = new javax.swing.JTextField();
- jTextFieldFromBase = new javax.swing.JTextField();
- jTextFieldToBase = new javax.swing.JTextField();
- jTextFieldResult = new javax.swing.JTextField();
- jMenuBar2 = new javax.swing.JMenuBar();
- jMenu1 = new javax.swing.JMenu();
- jMenuItem1 = new javax.swing.JMenuItem();
- jMenuItem2 = new javax.swing.JMenuItem();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setBackground(new java.awt.Color(204, 255, 204));
- jPanel1.setBackground(new java.awt.Color(0, 255, 153));
- jTextField1.setBackground(new java.awt.Color(204, 255, 204));
- jTextField1.setForeground(new java.awt.Color(0, 153, 51));
- jTextField1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jTextField1ActionPerformed(evt);
- }
- });
- jButtonPlusMin.setBackground(new java.awt.Color(204, 255, 204));
- jButtonPlusMin.setForeground(new java.awt.Color(0, 153, 0));
- jButtonPlusMin.setText("±");
- jButtonPlusMin.setActionCommand("jButtonPlusMin\n");
- jButtonPlusMin.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButtonPlusMinActionPerformed(evt);
- }
- });
- jButtonC.setBackground(new java.awt.Color(255, 255, 204));
- jButtonC.setForeground(new java.awt.Color(51, 153, 0));
- jButtonC.setText("C");
- jButtonC.setActionCommand("jButtonC");
- jButtonC.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButtonCActionPerformed(evt);
- }
- });
- jButtonRound.setBackground(new java.awt.Color(255, 255, 204));
- jButtonRound.setForeground(new java.awt.Color(51, 153, 0));
- jButtonRound.setText("round");
- jButtonRound.setActionCommand("jButtonRound");
- jButtonRound.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButtonRoundActionPerformed(evt);
- }
- });
- jButtonExit.setBackground(new java.awt.Color(255, 255, 204));
- jButtonExit.setForeground(new java.awt.Color(51, 153, 0));
- jButtonExit.setText("exit");
- jButtonExit.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButtonExitActionPerformed(evt);
- }
- });
- jButtonPlus.setBackground(new java.awt.Color(204, 255, 204));
- jButtonPlus.setForeground(new java.awt.Color(0, 153, 0));
- jButtonPlus.setText("+");
- jButtonPlus.setActionCommand("jButtonPlus\n");
- jButtonPlus.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButtonPlusActionPerformed(evt);
- }
- });
- jButtonSqrt.setBackground(new java.awt.Color(204, 255, 204));
- jButtonSqrt.setForeground(new java.awt.Color(0, 153, 0));
- jButtonSqrt.setText("√");
- jButtonSqrt.setActionCommand("jButtonSqrt");
- jButtonSqrt.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButtonSqrtActionPerformed(evt);
- }
- });
- jButtonQuadr.setBackground(new java.awt.Color(204, 255, 204));
- jButtonQuadr.setForeground(new java.awt.Color(0, 153, 0));
- jButtonQuadr.setText("x²");
- jButtonQuadr.setActionCommand("jButtonQuadr\n");
- jButtonQuadr.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButtonQuadrActionPerformed(evt);
- }
- });
- jButtonMin.setBackground(new java.awt.Color(204, 255, 204));
- jButtonMin.setForeground(new java.awt.Color(0, 153, 0));
- jButtonMin.setText("-");
- jButtonMin.setActionCommand("jButtonMin");
- jButtonMin.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButtonMinActionPerformed(evt);
- }
- });
- jButton7.setBackground(new java.awt.Color(255, 255, 204));
- jButton7.setForeground(new java.awt.Color(0, 153, 0));
- jButton7.setText("7");
- jButton7.setActionCommand("jButton7");
- jButton7.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton7ActionPerformed(evt);
- }
- });
- jButton8.setBackground(new java.awt.Color(255, 255, 204));
- jButton8.setForeground(new java.awt.Color(0, 153, 0));
- jButton8.setText("8");
- jButton8.setActionCommand("jButton8");
- jButton8.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton8ActionPerformed(evt);
- }
- });
- jButton9.setBackground(new java.awt.Color(255, 255, 204));
- jButton9.setForeground(new java.awt.Color(0, 153, 0));
- jButton9.setText("9");
- jButton9.setActionCommand("jButton9");
- jButton9.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton9ActionPerformed(evt);
- }
- });
- jButtonMult.setBackground(new java.awt.Color(204, 255, 204));
- jButtonMult.setForeground(new java.awt.Color(0, 153, 0));
- jButtonMult.setText("*");
- jButtonMult.setActionCommand("jButtonMult");
- jButtonMult.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButtonMultActionPerformed(evt);
- }
- });
- jButtonDiv.setBackground(new java.awt.Color(204, 255, 204));
- jButtonDiv.setForeground(new java.awt.Color(0, 153, 0));
- jButtonDiv.setText("/");
- jButtonDiv.setActionCommand("jButtonDiv");
- jButtonDiv.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButtonDivActionPerformed(evt);
- }
- });
- jButton4.setBackground(new java.awt.Color(255, 255, 204));
- jButton4.setForeground(new java.awt.Color(0, 153, 0));
- jButton4.setText("4");
- jButton4.setActionCommand("jButton4");
- jButton4.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton4ActionPerformed(evt);
- }
- });
- jButton5.setBackground(new java.awt.Color(255, 255, 204));
- jButton5.setForeground(new java.awt.Color(0, 153, 0));
- jButton5.setText("5");
- jButton5.setActionCommand("jButton5 ");
- jButton5.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton5ActionPerformed(evt);
- }
- });
- jButtonMod.setBackground(new java.awt.Color(204, 255, 204));
- jButtonMod.setForeground(new java.awt.Color(0, 153, 0));
- jButtonMod.setText("%");
- jButtonMod.setActionCommand("jButtonMod");
- jButtonMod.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButtonModActionPerformed(evt);
- }
- });
- jButton1getX.setBackground(new java.awt.Color(204, 255, 204));
- jButton1getX.setForeground(new java.awt.Color(0, 153, 0));
- jButton1getX.setText("1/x");
- jButton1getX.setActionCommand("jButton1getX");
- jButton1getX.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1getXActionPerformed(evt);
- }
- });
- jButton6.setBackground(new java.awt.Color(255, 255, 204));
- jButton6.setForeground(new java.awt.Color(0, 153, 0));
- jButton6.setText("6");
- jButton6.setActionCommand("jButton6");
- jButton6.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton6ActionPerformed(evt);
- }
- });
- jButton1.setBackground(new java.awt.Color(255, 255, 204));
- jButton1.setForeground(new java.awt.Color(0, 153, 0));
- jButton1.setText("1");
- jButton1.setActionCommand("jButton1");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jButtonDot.setBackground(new java.awt.Color(204, 255, 204));
- jButtonDot.setForeground(new java.awt.Color(0, 153, 0));
- jButtonDot.setText(".");
- jButtonDot.setActionCommand("jButtonDot");
- jButtonDot.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButtonDotActionPerformed(evt);
- }
- });
- jButton3.setBackground(new java.awt.Color(255, 255, 204));
- jButton3.setForeground(new java.awt.Color(0, 153, 0));
- jButton3.setText("3");
- jButton3.setActionCommand("jButton3");
- jButton3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton3ActionPerformed(evt);
- }
- });
- jButton2.setBackground(new java.awt.Color(255, 255, 204));
- jButton2.setForeground(new java.awt.Color(0, 153, 0));
- jButton2.setText("2");
- jButton2.setActionCommand("jButton2");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- jButtonEquals.setBackground(new java.awt.Color(204, 255, 204));
- jButtonEquals.setForeground(new java.awt.Color(0, 153, 0));
- jButtonEquals.setText("=");
- jButtonEquals.setActionCommand("jButtonEquals");
- jButtonEquals.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButtonEqualsActionPerformed(evt);
- }
- });
- jButton0.setBackground(new java.awt.Color(255, 255, 204));
- jButton0.setForeground(new java.awt.Color(0, 153, 0));
- jButton0.setText("0");
- jButton0.setActionCommand("jButton0");
- jButton0.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton0ActionPerformed(evt);
- }
- });
- jLabel1.setText("Decimal places:");
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(67, 67, 67)
- .addComponent(jButton0, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jLabel1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jTextFieldNachkst, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(14, 14, 14)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(10, 10, 10)
- .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jButtonMod))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(10, 10, 10)
- .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jButtonMult, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(10, 10, 10)
- .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButtonDot, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(jButtonDiv, javax.swing.GroupLayout.DEFAULT_SIZE, 43, Short.MAX_VALUE)
- .addComponent(jButtonEquals, javax.swing.GroupLayout.DEFAULT_SIZE, 43, Short.MAX_VALUE))
- .addComponent(jButton1getX)))
- .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
- .addComponent(jButtonPlusMin, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jButtonQuadr, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jButtonSqrt, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButtonPlus, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jButtonMin, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jButtonRound, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jButtonExit, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jButtonC, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))))))
- .addContainerGap(22, Short.MAX_VALUE))
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addContainerGap(18, Short.MAX_VALUE)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButtonRound)
- .addComponent(jButtonExit)
- .addComponent(jButtonC))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(18, 18, 18)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButtonPlusMin)
- .addComponent(jButtonQuadr)
- .addComponent(jButtonSqrt)
- .addComponent(jButtonPlus)
- .addComponent(jButtonMin))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButtonDiv)
- .addComponent(jButtonMult)
- .addComponent(jButton9)
- .addComponent(jButton8)
- .addComponent(jButton7))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1getX)
- .addComponent(jButtonMod)
- .addComponent(jButton6)
- .addComponent(jButton5)
- .addComponent(jButton4))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1)
- .addComponent(jButton2)
- .addComponent(jButton3)
- .addComponent(jButtonDot)
- .addComponent(jButtonEquals))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton0)
- .addComponent(jLabel1)
- .addComponent(jTextFieldNachkst, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addContainerGap(22, Short.MAX_VALUE))
- );
- jPanel3.setBackground(new java.awt.Color(102, 255, 255));
- jLabel6.setForeground(new java.awt.Color(0, 102, 102));
- jLabel6.setText("Number to convert: ");
- jLabel7.setForeground(new java.awt.Color(0, 102, 102));
- jLabel7.setText("from base:");
- jLabel8.setForeground(new java.awt.Color(0, 102, 102));
- jLabel8.setText("to base: ");
- jButtonConvert.setBackground(new java.awt.Color(204, 255, 204));
- jButtonConvert.setForeground(new java.awt.Color(0, 102, 102));
- jButtonConvert.setText("Convert");
- jButtonConvert.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButtonConvertActionPerformed(evt);
- }
- });
- jLabel9.setForeground(new java.awt.Color(0, 102, 102));
- jLabel9.setText("Result:");
- jTextFieldNumToConv.setBackground(new java.awt.Color(204, 255, 204));
- jTextFieldFromBase.setBackground(new java.awt.Color(204, 255, 204));
- jTextFieldFromBase.setForeground(new java.awt.Color(0, 153, 153));
- jTextFieldToBase.setBackground(new java.awt.Color(204, 255, 204));
- jTextFieldToBase.setForeground(new java.awt.Color(0, 153, 153));
- jTextFieldResult.setBackground(new java.awt.Color(204, 255, 204));
- jTextFieldResult.setForeground(new java.awt.Color(0, 153, 153));
- javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
- jPanel3.setLayout(jPanel3Layout);
- jPanel3Layout.setHorizontalGroup(
- jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel3Layout.createSequentialGroup()
- .addGap(20, 20, 20)
- .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel9)
- .addComponent(jButtonConvert)
- .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addGroup(jPanel3Layout.createSequentialGroup()
- .addComponent(jLabel8)
- .addGap(157, 157, 157)
- .addComponent(jTextFieldToBase, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
- .addComponent(jLabel7)
- .addGap(148, 148, 148)
- .addComponent(jTextFieldFromBase, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jTextFieldNumToConv, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addComponent(jTextFieldResult, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addContainerGap(24, Short.MAX_VALUE))
- );
- jPanel3Layout.setVerticalGroup(
- jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel3Layout.createSequentialGroup()
- .addGap(16, 16, 16)
- .addComponent(jLabel6)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jTextFieldNumToConv, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(18, 18, 18)
- .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel7)
- .addComponent(jTextFieldFromBase, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel8)
- .addComponent(jTextFieldToBase, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addComponent(jButtonConvert)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jLabel9)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jTextFieldResult, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(20, Short.MAX_VALUE))
- );
- jMenu1.setText("Options");
- jMenuItem1.setText("Calculator");
- jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jMenuItem1ActionPerformed(evt);
- }
- });
- jMenu1.add(jMenuItem1);
- jMenuItem2.setText("Base Convertion");
- jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jMenuItem2ActionPerformed(evt);
- }
- });
- jMenu1.add(jMenuItem2);
- jMenuBar2.add(jMenu1);
- setJMenuBar(jMenuBar2);
- 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()
- .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addContainerGap()))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(20, Short.MAX_VALUE))
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(34, Short.MAX_VALUE)))
- );
- pack();
- }// </editor-fold>
- StringBuffer sb = new StringBuffer();
- Stack<String> operation = new Stack<String>();
- // JFormattedTextField, EventObject getSource()
- private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jButtonPlusMinActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- jTextField1.setText("-");
- sb.append("-");
- operation.push("-");
- }
- private void jButtonCActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- jTextField1.setText("");
- sb.delete(0,100);
- }
- private void jButtonRoundActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- //sb.append(jTextField1.getText());
- //System.out.println("1Step:vzima text:" + sb.toString());
- jTextField1.setText(round(Double.parseDouble(
- jTextField1.getText()), Integer.parseInt
- (jTextFieldNachkst.getText())));
- sb.append("!");
- System.out.println("2Step:slaga tochka:"+sb.toString());
- operation.push("!");
- }
- private void jButtonExitActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- System.exit(0);
- }
- private void jButtonPlusActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- sb.append(jTextField1.getText());
- jTextField1.setText("");
- sb.append("+");
- operation.push("+");
- }
- private void jButtonMinActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- sb.append(jTextField1.getText());
- jTextField1.setText("");
- sb.append("-");
- operation.push("-");
- }
- private void jButtonMultActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- sb.append(jTextField1.getText());
- jTextField1.setText("");
- sb.append("*");
- operation.push("*");
- }
- private void jButtonDivActionPerformed(java.awt.event.ActionEvent evt) {
- sb.append(jTextField1.getText());
- jTextField1.setText("");
- sb.append("/");
- operation.push("/");
- }
- private void jButtonSqrtActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- sb.append(jTextField1.getText());
- jTextField1.setText("");
- sb.append("@");
- operation.push("@");
- }
- private void jButtonQuadrActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- sb.append(jTextField1.getText());
- jTextField1.setText("");
- sb.append("^");
- operation.push("^");
- }
- private void jButtonModActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- sb.append(jTextField1.getText());
- jTextField1.setText("");
- sb.append("%");
- operation.push("%");
- }
- private void jButton1getXActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- sb.append(jTextField1.getText());
- jTextField1.setText("");
- sb.append("$");
- operation.push("$");
- }
- private void jButtonDotActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- jTextField1.setText(jTextField1.getText() + ".");
- }
- StringBuffer undo=new StringBuffer();
- private void calculate() {
- String wahl = operation.peek();
- int i = sb.indexOf(wahl);
- double firstOperand = Double.parseDouble(sb.substring(1, i));
- sb.deleteCharAt(i);
- double secondOperand = Double.parseDouble(sb.substring(i));
- double ergebnis = 0;
- switch (wahl) {
- case "+":
- ergebnis = firstOperand + secondOperand;
- break;
- case "-":
- ergebnis = firstOperand - secondOperand;
- break;
- case "*":
- ergebnis = firstOperand * secondOperand;
- break;
- case "/":
- ergebnis = firstOperand / secondOperand;
- break;
- case "%": ergebnis=firstOperand % secondOperand;
- break;
- }
- undo.append(sb);
- sb.delete(1, 100);
- noDotNull(ergebnis);
- if(noDotNull(ergebnis) == true) {
- sb.append((int)ergebnis); }
- else {
- sb.append(ergebnis);
- }
- System.out.println(sb.toString());
- }
- private void calculateSpec() {
- String wahl = operation.peek();
- int i = sb.indexOf(wahl);
- double firstOperand = Double.parseDouble(sb.substring(1, i));
- sb.deleteCharAt(i);
- double ergebnis = 0;
- switch (wahl) {
- case "^":
- ergebnis = firstOperand * firstOperand;
- break;
- case "$":
- ergebnis = 1 / firstOperand;
- break;
- case "@":
- ergebnis = Math.sqrt(firstOperand);
- break;
- case "!": ergebnis= Double.parseDouble(round(firstOperand,Integer.parseInt(jTextFieldNachkst.getText())));
- break;
- }
- sb.delete(1, 100);
- noDotNull(ergebnis);
- System.out.println("Erg after rounding:" + ergebnis);
- if(noDotNull(ergebnis) == true) ergebnis = (int)ergebnis;
- sb.append(ergebnis);
- System.out.println(sb.toString());
- }
- public boolean noDotNull(double ergebnis)
- {
- int i = 1;
- for(;i<(int)ergebnis;i++)
- {
- if(ergebnis % i == 0)
- break;
- }
- return ergebnis % i == 0;
- }
- public String round(double erg,int nachkommastellen) {
- String x1 = jTextFieldNachkst.getText();
- nachkommastellen = Integer.parseInt(x1);
- /* Rundung */
- double s = Math.pow(10, nachkommastellen);
- double ergebnisl = Math.round(erg * s) / s;
- return String.valueOf(ergebnisl);
- }
- private void numberListener(JButton button) {
- if (sb.length()==0){
- jTextField1.setText(button.getText());
- sb.append("#");
- } else {
- jTextField1.setText(jTextField1.getText()+ button.getText());
- }
- }
- private void jButtonEqualsActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- sb.append(jTextField1.getText());
- if (operation.peek()=="@" || operation.peek()== "^" || operation.peek()=="$" || operation.peek()=="!") {
- calculateSpec();
- } else {
- calculate();
- System.out.println("Golemina na SB:" + sb.length());
- }
- jTextField1.setText(sb.substring(1));
- sb.delete(1,100);
- System.out.println("Golemina na SB:" + sb.length());
- System.out.println("Sled =:"+sb.toString());
- }
- private void jButton0ActionPerformed(java.awt.event.ActionEvent evt) {
- numberListener(jButton0);
- }
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- numberListener(jButton1);
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- numberListener(jButton2);
- }
- private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
- numberListener(jButton3);
- }
- private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
- numberListener(jButton4);
- }
- private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
- numberListener(jButton5);
- }
- private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
- numberListener(jButton6);
- }
- private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
- numberListener(jButton7);
- }
- private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {
- numberListener(jButton8);
- }
- private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {
- numberListener(jButton9);
- }
- /* Methods for the second Panel */
- private void jButtonConvertActionPerformed(java.awt.event.ActionEvent evt) {
- DisplayNumber number;
- number = new DisplayNumber(jTextFieldNumToConv.getText(),
- Integer.parseInt(jTextFieldFromBase.getText()));
- jTextFieldResult.setText(number.displayInBase
- (Integer.parseInt(jTextFieldToBase.getText())));
- }
- private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
- jPanel1.setVisible(false);
- jPanel3.setVisible(true);
- }
- private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
- jPanel3.setVisible(false);
- jPanel1.setVisible(true);
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /*
- * Set the Nimbus look and feel
- */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /*
- * If Nimbus (introduced in Java SE 6) is not available, stay with the
- * default look and feel. For details see
- * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(GrafOb.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /*
- * Create and display the form
- */
- java.awt.EventQueue.invokeLater(new Runnable() {
- @Override
- public void run() {
- new GrafOb().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButton0;
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButtonConvert;
- private javax.swing.JButton jButton1getX;
- private javax.swing.JButton jButton2;
- private javax.swing.JButton jButton3;
- private javax.swing.JButton jButton4;
- 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.JButton jButtonC;
- private javax.swing.JButton jButtonDiv;
- private javax.swing.JButton jButtonDot;
- private javax.swing.JButton jButtonEquals;
- private javax.swing.JButton jButtonExit;
- private javax.swing.JButton jButtonMin;
- private javax.swing.JButton jButtonMod;
- private javax.swing.JButton jButtonMult;
- private javax.swing.JButton jButtonPlus;
- private javax.swing.JButton jButtonPlusMin;
- private javax.swing.JButton jButtonQuadr;
- private javax.swing.JButton jButtonRound;
- private javax.swing.JButton jButtonSqrt;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel6;
- private javax.swing.JLabel jLabel7;
- private javax.swing.JLabel jLabel8;
- private javax.swing.JLabel jLabel9;
- private javax.swing.JMenu jMenu1;
- private javax.swing.JMenuBar jMenuBar2;
- private javax.swing.JMenuItem jMenuItem1;
- private javax.swing.JMenuItem jMenuItem2;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JPanel jPanel3;
- private javax.swing.JTextField jTextField1;
- private javax.swing.JTextField jTextFieldNumToConv;
- private javax.swing.JTextField jTextFieldFromBase;
- private javax.swing.JTextField jTextFieldToBase;
- private javax.swing.JTextField jTextFieldResult;
- private javax.swing.JTextField jTextFieldNachkst;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement