campo double valor; //guardado campo apos escolher a operacao String op =""; //guarda a operacao escolhida int b = 0; /** * Creates newform jFTela */ public jFTela() { initComponents(); } /** * This method iscalled from within the constructor to initialize the form. * WARNING: Do NOTmodify this code. The content of this method is always * regenerated bythe Form Editor. */ @SuppressWarnings("unchecked") // <editor-folddefaultstate="collapsed" desc="Generated Code"> private voidinitComponents() { jPanel1 = newjavax.swing.JPanel(); jTCampo = newjavax.swing.JTextField(); jBUm = newjavax.swing.JButton(); jBDois = newjavax.swing.JButton(); jBTres = newjavax.swing.JButton(); jBQuatro = newjavax.swing.JButton(); jBSoma = newjavax.swing.JButton(); jBSubtrair =new javax.swing.JButton(); jBMultiplicar= new javax.swing.JButton(); jBDividir =new javax.swing.JButton(); jBIgual = newjavax.swing.JButton(); jBLimpar = newjavax.swing.JButton(); jBCinco = new javax.swing.JButton(); jBSeis = newjavax.swing.JButton(); jBSete = newjavax.swing.JButton(); jBOito = newjavax.swing.JButton(); jBNove = newjavax.swing.JButton(); jBZero = newjavax.swing.JButton(); jLTela = newjavax.swing.JLabel(); jLabel1 = newjavax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jBUm.setText("1"); jBUm.addActionListener(new java.awt.event.ActionListener() { publicvoid actionPerformed(java.awt.event.ActionEvent evt) { jBUmActionPerformed(evt); } }); jBDois.setText("2"); jBDois.addActionListener(newjava.awt.event.ActionListener() { publicvoid actionPerformed(java.awt.event.ActionEvent evt) { jBDoisActionPerformed(evt); } }); jBTres.setText("3"); jBTres.addActionListener(new java.awt.event.ActionListener() { publicvoid actionPerformed(java.awt.event.ActionEvent evt) { jBTresActionPerformed(evt); } }); jBQuatro.setText("4"); jBQuatro.addActionListener(new java.awt.event.ActionListener() { publicvoid actionPerformed(java.awt.event.ActionEvent evt) { jBQuatroActionPerformed(evt); } }); jBSoma.setText("+"); jBSoma.addActionListener(new java.awt.event.ActionListener() { publicvoid actionPerformed(java.awt.event.ActionEvent evt) { jBSomaActionPerformed(evt); } }); jBSubtrair.setText("-"); jBSubtrair.addActionListener(newjava.awt.event.ActionListener() { publicvoid actionPerformed(java.awt.event.ActionEvent evt) { jBSubtrairActionPerformed(evt); } }); jBMultiplicar.setText("x"); jBMultiplicar.addActionListener(newjava.awt.event.ActionListener() { publicvoid actionPerformed(java.awt.event.ActionEvent evt) { jBMultiplicarActionPerformed(evt); } }); jBDividir.setText("/"); jBDividir.addActionListener(new java.awt.event.ActionListener() { publicvoid actionPerformed(java.awt.event.ActionEvent evt) { jBDividirActionPerformed(evt); } }); jBIgual.setText("="); jBIgual.addActionListener(newjava.awt.event.ActionListener() { publicvoid actionPerformed(java.awt.event.ActionEvent evt) { jBIgualActionPerformed(evt); } }); jBLimpar.setText("C"); jBLimpar.addActionListener(new java.awt.event.ActionListener() { publicvoid actionPerformed(java.awt.event.ActionEvent evt) { jBLimparActionPerformed(evt); } }); jBCinco.setText("5"); jBCinco.addActionListener(newjava.awt.event.ActionListener() { publicvoid actionPerformed(java.awt.event.ActionEvent evt) { jBCincoActionPerformed(evt); } }); jBSeis.setText("6"); jBSeis.addActionListener(newjava.awt.event.ActionListener() { publicvoid actionPerformed(java.awt.event.ActionEvent evt) { jBSeisActionPerformed(evt); } }); jBSete.setText("7"); jBSete.addActionListener(new java.awt.event.ActionListener() { publicvoid actionPerformed(java.awt.event.ActionEvent evt) { jBSeteActionPerformed(evt); } }); jBOito.setText("8"); jBOito.addActionListener(new java.awt.event.ActionListener() { publicvoid actionPerformed(java.awt.event.ActionEvent evt) { jBOitoActionPerformed(evt); } }); jBNove.setText("9"); jBNove.addActionListener(newjava.awt.event.ActionListener() { publicvoid actionPerformed(java.awt.event.ActionEvent evt) { jBNoveActionPerformed(evt); } }); jBZero.setText("0"); jBZero.addActionListener(newjava.awt.event.ActionListener() { publicvoid actionPerformed(java.awt.event.ActionEvent evt) { jBZeroActionPerformed(evt); } }); jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N jLabel1.setText(" CALCULADORA"); javax.swing.GroupLayout jPanel1Layout = newjavax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLTela, javax.swing.GroupLayout.DEFAULT_SIZE,javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE,javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,false) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jBUm) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jBQuatro)) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jBDois) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jBCinco)) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jBTres) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jBSeis))) .addGap(5, 6,Short.MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jBNove) .addComponent(jBSete)) .addComponent(jBOito, javax.swing.GroupLayout.Alignment.TRAILING))) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,false) .addComponent(jBMultiplicar, javax.swing.GroupLayout.Alignment.LEADING,javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,Short.MAX_VALUE) .addComponent(jBSoma,javax.swing.GroupLayout.Alignment.LEADING,javax.swing.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE)) .addGap(18, 18,18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jBSubtrair, javax.swing.GroupLayout.DEFAULT_SIZE,javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jBDividir,javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,Short.MAX_VALUE)))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jBIgual) .addComponent(jBLimpar) .addComponent(jBZero))) .addComponent(jTCampo)) .addContainerGap()) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 31,Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jTCampo, 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.LEADING,false) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jBUm) .addComponent(jBQuatro) .addComponent(jBSete)) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jBDois) .addComponent(jBCinco) .addComponent(jBOito))) .addComponent(jBIgual, javax.swing.GroupLayout.DEFAULT_SIZE,javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jBTres) .addComponent(jBSeis) .addComponent(jBNove) .addComponent(jBZero)) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jBSoma) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jBMultiplicar) .addComponent(jBDividir))) .addComponent(jBSubtrair))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,jPanel1Layout.createSequentialGroup() .addGap(8, 8, 8) .addComponent(jBLimpar, javax.swing.GroupLayout.PREFERRED_SIZE, 55,javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLTela, javax.swing.GroupLayout.PREFERRED_SIZE, 35,javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); javax.swing.GroupLayout layout = newjavax.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)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap()) ); pack(); }// </editor-fold> private voidjBUmActionPerformed(java.awt.event.ActionEvent evt) { // TODO addyour handling code here: if(b!=0){ jTCampo.setText(""); } jTCampo.setText(jTCampo.getText() + 1); //Acrescenta ovalor no campo a =Double.valueOf(jTCampo.getText()); //guarda o valor digitado no campo } private voidjBDoisActionPerformed(java.awt.event.ActionEvent evt) { // TODO addyour handling code here: if(b!=0){ //vaigarantir que caso tenha clicado em = zere