Ir ao conteúdo
  • Cadastre-se

welder.a

Membro Júnior
  • Posts

    17
  • Cadastrado em

  • Última visita

posts postados por welder.a

  1. Este local que adicionei deve estar errado :-/.

    Sou leigo e pra mim até para colar o código se eu não souber o local já me complico.

    coloquei aqui mas da erro

     

    private void btnjogarActionPerformed(java.awt.event.ActionEvent evt) {                                         
         try{
             int numero = Integer.parseInt(txtnumero.getText());
             
             if(numero== aleatorio){
                 txtsaida.append("Acertou\n");
                 btnjogar.setEnabled(false);
                 btnreiniciar.setEnabled(true); 
             }
             
             else if(numero <aleatorio)
                 txtsaida.append(numero+"Mais Perto\n");
             txtnumero.setBackground(Color.blue); //COLOQUEI AQUI E EXECUTEI MAS DA ERRO DURANTE
                 
             else if (numero> aleatorio)
                 txtsaida.append(numero+"Mais Longe\n");
             txtnumero.setBackground(Color.blue);//NESTE CAMPO
             
             txtnumero.setText("");
             txtnumero.requestFocus();
             txtnumero.repaint();// E NESTE LOCAL

     

    ele muda a cor mas meio que fica um caminho para completar, que quando digito no Jtext ele muda o fundo, apenas uma vez, ocorre o erro não mudar mais e o jogo não continua

     

    mas ja agradeço sua atenção e ajuda da mesma forma, já deu uma clareada.

    Depois ainda tenho que me preocupar com um (Jlabel) apresentar "Mais Perto " ou "Mais longe "

  2. Olá boa noite a todos se alguém por favor conseguir me ajudar neste problema fico agradecido!!
    Por favor poste o CÓDIGO!!!☼

    Um **JtextField** deve ser usado para a captura do valor. Para cada tentativa de adivinhação a cor de fundo deve mudar para Vermelho ou Azul. Vermelho indica que o usuário está chegando mais perto e azul indica que o usuário esta se afastando do numero. Um **Jlabel** deve mostrar ou "Mais Perto" ou "Mais Longe".

    POR ENQUANTO FIZ ISSO JÁ

     

    private void btnjogarActionPerformed(java.awt.event.ActionEvent evt) {                                         
         try{
             int numero = Integer.parseInt(txtnumero.getText());
             
             if(numero== aleatorio){
                 txtsaida.append("Acertou\n");
                 btnjogar.setEnabled(false);
                 btnreiniciar.setEnabled(true); 
             }
             else if(numero <aleatorio)
                 txtsaida.append(numero+"Mais Perto\n");
                 
             else if (numero>aleatorio)
                 txtsaida.append(numero+"Mais Longe\n");
             
             txtnumero.setText("");
             txtnumero.requestFocus();
             
         }catch(NumberFormatException ex){
             JOptionPane.showInputDialog(null, ex.getMessage());    
         }
        }                                        

        private void btnreiniciarActionPerformed(java.awt.event.ActionEvent evt) {                                             
            btnjogar.setEnabled(true);
            btnreiniciar.setEnabled(false);
            aleatorio = (int)(Math.random()*10);
            txtnumero.requestFocus();
        }                                            

        private void txtnumeroActionPerformed(java.awt.event.ActionEvent evt) {                                          

        }

  3. Tenta ver primeiramente se o problema não é em um driver Desatualizado.

    Se não for procura ver se as portas USB que você está plugando estão funcionando, colocando um pendrive com luz.

    Se ascender Ok, o problema não está na porta que está utilizando, ai voce ira ver se o adaptador esta funcionando.

    Tente colocar em outra porta. Veja se na hora da limpeza de seu gabinete não caiu poeira nas entradas. Teste em outro pc (se tiver).

    espero ter ajudado!

  4. Olá a todos peço uma ajuda. Não sei porque está dando erro na minha progamação ja tentei consertar de diversos modo mas não sai o erro

    *Obs: Sou leigo em Java

     

    A quem puder agradeço!!

     

    package Telas;

    import javax.swing.JOptionPane;

    /**
     *
     * @author update
     */
    public class CalculadoraJFrame extends javax.swing.JFrame {

        double num1, num2, resultado;
        char operacao;

        /**
         * Creates new form CalculadoraJFrame
         */
        public CalculadoraJFrame() {
            initComponents();

            jPanel1.setFocusable(true);
    //        lbTela.setBorder (new EtchedBorder());
        }

        /**
         * 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.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
            bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

            jPanel1 = new javax.swing.JPanel();
            btseis = new javax.swing.JButton();
            bttres = new javax.swing.JButton();
            btsete = new javax.swing.JButton();
            btponto = new javax.swing.JButton();
            btquatro = new javax.swing.JButton();
            btdividir = new javax.swing.JButton();
            btum = new javax.swing.JButton();
            btmultiplicar = new javax.swing.JButton();
            btc = new javax.swing.JButton();
            btsubtrair = new javax.swing.JButton();
            btoito = new javax.swing.JButton();
            btsomar = new javax.swing.JButton();
            btcinco = new javax.swing.JButton();
            btigual = new javax.swing.JButton();
            btdois = new javax.swing.JButton();
            btraizquadrada = new javax.swing.JButton();
            btzero = new javax.swing.JButton();
            btnove = new javax.swing.JButton();
            lbTela = new javax.swing.JLabel();
            btBackspace = new javax.swing.JButton();
            lbTemp = new javax.swing.JLabel();

            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setBackground(new java.awt.Color(0, 153, 204));

            jPanel1.setBackground(new java.awt.Color(204, 204, 255));
            jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
            jPanel1.setForeground(new java.awt.Color(0, 204, 204));
            jPanel1.setToolTipText("Calculadora");
            jPanel1.addKeyListener(new java.awt.event.KeyAdapter() {
                public void keyPressed(java.awt.event.KeyEvent evt) {
                    jPanel1KeyPressed(evt);
                }
            });

            btseis.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            btseis.setText("6");
            btseis.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btseisActionPerformed(evt);
                }
            });

            bttres.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            bttres.setText("3");
            bttres.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    bttresActionPerformed(evt);
                }
            });

            btsete.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            btsete.setText("7");
            btsete.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btseteActionPerformed(evt);
                }
            });

            btponto.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            btponto.setText(".");
            btponto.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btpontoActionPerformed(evt);
                }
            });

            btquatro.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            btquatro.setText("4");
            btquatro.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btquatroActionPerformed(evt);
                }
            });

            btdividir.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            btdividir.setText("/");
            btdividir.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btdividirActionPerformed(evt);
                }
            });

            btum.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            btum.setText("1");
            btum.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btumActionPerformed(evt);
                }
            });

            btmultiplicar.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            btmultiplicar.setText("X");
            btmultiplicar.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btmultiplicarActionPerformed(evt);
                }
            });

            btc.setFont(new java.awt.Font("Times New Roman", 1, 10)); // NOI18N
            btc.setText("C");
            btc.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btcActionPerformed(evt);
                }
            });

            btsubtrair.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            btsubtrair.setText("-");
            btsubtrair.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btsubtrairActionPerformed(evt);
                }
            });

            btoito.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            btoito.setText("8");
            btoito.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btoitoActionPerformed(evt);
                }
            });

            btsomar.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
            btsomar.setText("+");
            btsomar.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btsomarActionPerformed(evt);
                }
            });

            btcinco.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            btcinco.setText("5");
            btcinco.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btcincoActionPerformed(evt);
                }
            });

            btigual.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
            btigual.setText("=");
            btigual.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btigualActionPerformed(evt);
                }
            });

            btdois.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            btdois.setText("2");
            btdois.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btdoisActionPerformed(evt);
                }
            });

            btraizquadrada.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            btraizquadrada.setText("√");
            btraizquadrada.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btraizquadradaActionPerformed(evt);
                }
            });

            btzero.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            btzero.setText("0");
            btzero.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btzeroActionPerformed(evt);
                }
            });

            btnove.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            btnove.setText("9");
            btnove.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btnoveActionPerformed(evt);
                }
            });

            lbTela.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
            lbTela.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
            lbTela.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

            org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, btc, org.jdesktop.beansbinding.ELProperty.create("${horizontalAlignment}"), lbTela, org.jdesktop.beansbinding.BeanProperty.create("horizontalAlignment"));
            bindingGroup.addBinding(binding);

            btBackspace.setText("BackSpace");
            btBackspace.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btBackspaceActionPerformed(evt);
                }
            });

            lbTemp.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

            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(45, 45, 45)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(lbTela, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                                    .addComponent(btquatro)
                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                    .addComponent(btcinco))
                                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                                    .addComponent(btsete)
                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                    .addComponent(btoito))
                                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                                    .addComponent(btum)
                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                    .addComponent(btdois))
                                                .addGroup(jPanel1Layout.createSequentialGroup()
                                                    .addComponent(btc)
                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                    .addComponent(btzero)))
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(bttres)
                                                    .addComponent(btseis))
                                                .addComponent(btponto)
                                                .addComponent(btnove, javax.swing.GroupLayout.Alignment.LEADING)))
                                        .addComponent(btBackspace, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGap(18, 18, 18)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(btigual, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(btsubtrair, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(btmultiplicar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(btdividir, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(btraizquadrada, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(btsomar, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(32, 32, 32)
                            .addComponent(lbTemp, javax.swing.GroupLayout.PREFERRED_SIZE, 279, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap(25, Short.MAX_VALUE))
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(61, 61, 61)
                    .addComponent(lbTemp, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(lbTela, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(btdividir)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(btmultiplicar)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(btsubtrair, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(btraizquadrada, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(btoito)
                                .addComponent(btsete)
                                .addComponent(btnove))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(btseis)
                                .addComponent(btcinco)
                                .addComponent(btquatro))
                            .addGap(7, 7, 7)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(btum)
                                .addComponent(bttres)
                                .addComponent(btdois))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(btc, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(btzero, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(btponto, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addComponent(btsomar, 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, false)
                        .addComponent(btigual, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btBackspace, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addContainerGap())
            );

            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addGap(0, 3, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            );

            jPanel1.getAccessibleContext().setAccessibleName("Calculadora");

            bindingGroup.bind();

            pack();
        }// </editor-fold>                        

        private void btumActionPerformed(java.awt.event.ActionEvent evt) {                                     
            setarNumerosNoLbTela('1');
        }                                    

        private void btdoisActionPerformed(java.awt.event.ActionEvent evt) {                                       
            setarNumerosNoLbTela('2');
        }                                      

        private void bttresActionPerformed(java.awt.event.ActionEvent evt) {                                       
            setarNumerosNoLbTela('3');
        }                                      

        private void btquatroActionPerformed(java.awt.event.ActionEvent evt) {                                         
            setarNumerosNoLbTela('4');
        }                                        

        private void btcincoActionPerformed(java.awt.event.ActionEvent evt) {                                        
            setarNumerosNoLbTela('5');
        }                                       

        private void btseisActionPerformed(java.awt.event.ActionEvent evt) {                                       
            setarNumerosNoLbTela('6');
        }                                      

        private void btseteActionPerformed(java.awt.event.ActionEvent evt) {                                       
            setarNumerosNoLbTela('7');
        }                                      

        private void btoitoActionPerformed(java.awt.event.ActionEvent evt) {                                       
            setarNumerosNoLbTela('8');
        }                                      

        private void btnoveActionPerformed(java.awt.event.ActionEvent evt) {                                       
            setarNumerosNoLbTela('9');
        }                                      

        private void btzeroActionPerformed(java.awt.event.ActionEvent evt) {                                       
            setarNumerosNoLbTela('0');
        }                                      

        private void btpontoActionPerformed(java.awt.event.ActionEvent evt) {                                        
            setarNumerosNoLbTela('.');
        }                                       

        private void btsomarActionPerformed(java.awt.event.ActionEvent evt) {                                        
            pegarNum1();

            operacao = '+';
            setarValoresLbTemp();
        }                                       

        private void btdividirActionPerformed(java.awt.event.ActionEvent evt) {                                          
            pegarNum1();

            operacao = '/';
            setarValoresLbTemp();
        }                                         

        private void btsubtrairActionPerformed(java.awt.event.ActionEvent evt) {                                           
            pegarNum1();

            operacao = '-';
            setarValoresLbTemp();
        }                                          

        private void btmultiplicarActionPerformed(java.awt.event.ActionEvent evt) {                                              
            pegarNum1();

            operacao = '*';
            setarValoresLbTemp();
        }                                             

        private void btigualActionPerformed(java.awt.event.ActionEvent evt) {                                        
            pegarNum2();
            calcular();
            lbTemp.setText(lbTemp.getText() + " " + num2);
        }                                       

        private void btcActionPerformed(java.awt.event.ActionEvent evt) {                                    
            reiniciarCalculadora();
            jPanel1.requestFocus();
        }                                   


        private void btBackspaceActionPerformed(java.awt.event.ActionEvent evt) {                                            
            backspace();
        }                                           

        private void btraizquadradaActionPerformed(java.awt.event.ActionEvent evt) {                                               
            pegarNum1();

            operacao = '√';
            calcular();
            setarValoresLbTemp();
        }                                              

        private void jPanel1KeyPressed(java.awt.event.KeyEvent evt) {                                   
            if (evt.getKeyChar() == '0'
                    || evt.getKeyChar() == '1'
                    || evt.getKeyChar() == '2'
                    || evt.getKeyChar() == '3'
                    || evt.getKeyChar() == '4'
                    || evt.getKeyChar() == '5'
                    || evt.getKeyChar() == '6'
                    || evt.getKeyChar() == '7'
                    || evt.getKeyChar() == '8'
                    || evt.getKeyChar() == '9') {
                setarNumerosNoLbTela(evt.getKeyChar());
        }                                  
            else if (evt.getKeyChar() == '-'    
             ||evt.getKeyChar() == '+'
             ||evt.getKeyChar() == '/'
             ||evt.getKeyChar() == '*' )
            {
        pegarNum1();

        operacao = evt.getKeyChar();
        setarValoresLbTemp();
        {   
            else if(evt.getKeyCode()==10){  
             pegarNum2();
             calcular();
            lbTemp.setText(lbTemp.getText() + " " + num2);   
            } else if(evt.getKeyCode()==8);
            {
             backspace();
            }
              
            /**
             * @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 ex) {
                java.util.logging.Logger.getLogger(CalculadoraJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(CalculadoraJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(CalculadoraJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(CalculadoraJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>

            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new CalculadoraJFrame().setVisible(true);
                }
            });
        }

        // Variables declaration - do not modify                     
        private javax.swing.JButton btBackspace;
        private javax.swing.JButton btc;
        private javax.swing.JButton btcinco;
        private javax.swing.JButton btdividir;
        private javax.swing.JButton btdois;
        private javax.swing.JButton btigual;
        private javax.swing.JButton btmultiplicar;
        private javax.swing.JButton btnove;
        private javax.swing.JButton btoito;
        private javax.swing.JButton btponto;
        private javax.swing.JButton btquatro;
        private javax.swing.JButton btraizquadrada;
        private javax.swing.JButton btseis;
        private javax.swing.JButton btsete;
        private javax.swing.JButton btsomar;
        private javax.swing.JButton btsubtrair;
        private javax.swing.JButton bttres;
        private javax.swing.JButton btum;
        private javax.swing.JButton btzero;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JLabel lbTela;
        private javax.swing.JLabel lbTemp;
        private org.jdesktop.beansbinding.BindingGroup bindingGroup;
        // End of variables declaration                   

        public void setarNumerosNoLbTela(char numero) {
            if ("0".equals(lbTela.getText()) && !".".equals(String.valueOf(numero))) {
                lbTela.setText("");
            }
            String texto = lbTela.getText();
            
            if (texto.length() <= 15) {
                texto = texto + numero;
                lbTela.setText(texto);

                jPanel1.requestFocus();
            }

        }

        public void pegarNum1() {
            num1 = Double.parseDouble(lbTela.getText());
            lbTela.setText("0");
            jPanel1.requestFocus();
        }

        public void pegarNum2() {
            num2 = Double.parseDouble(lbTela.getText());
            lbTela.setText("");
        }

        public void calcular() {
            if (num2 == 0 && operacao == '/') {
                JOptionPane.showMessageDialog(null, "Operação Inválida!");
                reiniciarCalculadora();
            } else {
                if (operacao == '+') {
                    resultado = num1 + num2;
                } else if (operacao == '/') {
                    resultado = num1 / num2;
                } else if (operacao == '-') {
                    resultado = num1 - num2;
                } else if (operacao == '*') {
                    resultado = num1 * num2;
                } else {
                    resultado = Math.sqrt(num1);
                }
                lbTela.setText(String.valueOf(resultado));
                jPanel1.requestFocus();
            }
        }

        public void setarValoresLbTemp() {
            lbTemp.setText(num1 + " " + operacao);
        }

        public void reiniciarCalculadora() {
            num1 = 0;
            num2 = 0;
            resultado = 0;
            lbTela.setText("0");
            lbTemp.setText("");
        }

        /**
         *
         */
        public void backspace() {
            String valor_do_lbTela = lbTela.getText();

            if (valor_do_lbTela.length() > 1) {
                if (".".equals(valor_do_lbTela.substring(valor_do_lbTela.length() - 2, valor_do_lbTela.length() - 1))) {
                    valor_do_lbTela = valor_do_lbTela.substring(0, valor_do_lbTela.length() - 2);
                } else {
                    valor_do_lbTela = valor_do_lbTela.substring(0, valor_do_lbTela.length() - 1);
                }

                lbTela.setText(valor_do_lbTela);

                if (valor_do_lbTela.length() == 0) {
                    lbTela.setText("0");
                }
            } else {
                lbTela.setText("0");
            }

            jPanel1.requestFocus();
        }
    public void limitarCaracteres(){
        
        } 
    }

  5. Olá boa noite a quem está lendo

    Venho fazendo trabalhos de java para compensação de notas e estou perdido.

    Havia pedido ajuda aqui mesmo e uma grande pessoa conseguiu resolver um problema para mim, mas resta estes dois :-(

    Sei que se eu pesquisar no Google vai aparecer mas realmente não estou conseguindo, peço um pouco do conhecimento de alguem que possa.

    Obrigado desde já .

     

    Se alguem puder sem querer pedir muito.. Postar o codigo aqui!!

    * SÃO ESTES DOIS ARQUIVOS. 

    Adivinhe.rar

    Calculadora3.rar

  6. Olá a todos do Clube do Hardware!

    Quero pedir uma ajuda a quem possa, claro!

    Estou fazendo um trabalho para compensação de nota e realmente estou um pouco perdido em progamação. São coisas que devem ser SIMPLES, mas não estou conseguindo :-/.

    Esse do jogo "Adivinhe", esta faltando colocar fundo de cor Vermelho para "Mais Perto" e Azul para "Mais Longe" no JTextField já utlizado para captura do valor.

    Também não consegui colocar os dados de "Mais Perto" e "Mais Longe" no JLabel quando estiver executando e jogando.

    Esse que estou fazendo agora funciona "certinho" que é o 

    "abreimagem", mas o NetBeans diz haver um erro no private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt).

    Irei fazer mais quatro trabalho desse tipo, se eu puder contar com a sua ajuda. 

     

    Sei que se eu buscar no google talvez posso até encontrar... Mas mesmo assim ta difícil para eu!

    se alguem conseguir me ajudar, de verdade estarei grato

    Abreimagem.rar

    Adivinhe.rar

    Calculadora3.rar

  7. Boa noite Prezados!

     

    Estou tentando fazer contagem de registros, assim como soma de valores, Média de valores e Calculo de datas e estou tendo dificuldades.

    Alguem poderia me ajudar?

     

    Minha Progamação é esta:

    create database Cadastro
    default character set utf8
    default collate utf8_general_ci;
    use cadastro;
    create table aluno(
    id int not null auto_increment,
    Nome varchar (20) not null,
    Nascimento date,
    Sexo enum ('M','F'),
    Peso decimal (5,2),
    Altura decimal (3,2),
    Nacionalidade varchar (20),
    Endereco varchar (100),
    Telefone varchar (15),
    Email varchar (45),
    primary key (id)
    ) default charset =utf8;
    select * from aluno;


     

     

  8. Bom dia a todos !

     

    Tenho um kit Mouse e Teclado Wireless Microsoft 800, o teclado liga normalmente e funciona, porém o mouse liga mas parece não estar trocando sinal com receptor.

    O que pode ser? Há uma forma de ajustar a frequência seja por Software ou hardware ?. E no caso. Tenho dois Mouse da mesma marca e modelo, apenas um é de 2013 e o outro de 2015, consigo ligar  ele ao receptor ?

    Agradeço desde já a força!! ;-)

  9. Tenho um Computador nestes quesitos:

    Processador Core 2 Quad Q8400;

    placa-mãe LX2BR DDR3;

    Memoria Ram 2x4 GB Kingstone;

    HD de 500GB;

    E agora pretendo comprar esta placa de video: GALAX GTX 1050 TI OC 4GB GDDR5

    porém minha fonte é uma Wisecase de 500w "Reais"

    Minha pergunta é, qual uma fonte de 500w seja mais em conta? Está placa de video vai dar gargalo no pc com essas configurações?

    Agradeço desde já

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

Ebook grátis: Aprenda a ler resistores e capacitores!

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!