(RESOLVIDO) - Aparecendo numero 00000001

Olá pessoal, esse é meu primeiro tópico aqui no Guj, sou iniciante java e qualquer dica é de grande importância pra mim.
Quando eu executo este programa e utilizo o varlor 3 na quantidade do item bola de gude aparece o número 00000001 no total do mesmo, não sei o que pode ser. x_x
Estou usando o WindowBuilder.
desde já agradeço.

package Visual;

import java.awt.EventQueue;

public class teste {

	private JFrame frame;
	private JTextField textNome;
	private JLabel lblBolaDeGude;
	private JTextField textQuantGude;
	private JTextField textValorGude;
	private JTextField textTotal_Gude;
	private JLabel lblQuant;
	private JLabel lblValorUnitrio;
	private JLabel lblTotal;
	private JTextField textQuantQuete;
	private JTextField textValorQuete;
	private JTextField textTotal_Quete;
	private JTextField textQuantLiche;
	private JTextField textValorLiche;
	private JTextField textTotal_Liche;
	private JLabel lblBolaDeBasquete;
	private JLabel lblBolaDeBoliche;
	private JTextField textTotal_Total;
	private JButton btnCalculando;
	private JLabel lblTotal_1;
	private JLabel lblR;
	private JLabel label;
	private JLabel label_1;

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					teste window = new teste();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	public teste() {
		initialize();
	}
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 464, 269);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		frame.setTitle("EXERCICIO 3.2");
		
		JLabel lblNome = new JLabel("Nome");
		lblNome.setBounds(10, 11, 46, 14);
		frame.getContentPane().add(lblNome);
		
		textNome = new JTextField();
		textNome.setBounds(66, 8, 139, 20);
		frame.getContentPane().add(textNome);
		textNome.setColumns(10);
		
		JLabel lblItensComprados = new JLabel("Itens comprados");
		lblItensComprados.setFont(new Font("Tahoma", Font.BOLD, 13));
		lblItensComprados.setBounds(66, 41, 119, 14);
		frame.getContentPane().add(lblItensComprados);
		
		lblBolaDeGude = new JLabel("Bola de gude");
		lblBolaDeGude.setBounds(66, 68, 119, 14);
		frame.getContentPane().add(lblBolaDeGude);
		
		textQuantGude = new JTextField();
		textQuantGude.setBounds(195, 62, 41, 20);
		frame.getContentPane().add(textQuantGude);
		textQuantGude.setColumns(10);
		
		textValorGude = new JTextField();
		textValorGude.setBackground(UIManager.getColor("Button.background"));
		textValorGude.setEditable(false);
		textValorGude.setBounds(255, 62, 70, 20);
		frame.getContentPane().add(textValorGude);
		textValorGude.setColumns(10);
		
		
		textTotal_Gude = new JTextField();
		textTotal_Gude.setBackground(UIManager.getColor("Button.background"));
		textTotal_Gude.setEditable(false);
		textTotal_Gude.setBounds(335, 62, 59, 20);
		frame.getContentPane().add(textTotal_Gude);
		textTotal_Gude.setColumns(10);
		
		lblQuant = new JLabel("Quant");
		lblQuant.setFont(new Font("Tahoma", Font.BOLD, 11));
		lblQuant.setBounds(201, 41, 35, 14);
		frame.getContentPane().add(lblQuant);
		
		lblValorUnitrio = new JLabel("Valor Unit\u00E1rio");
		lblValorUnitrio.setFont(new Font("Tahoma", Font.BOLD, 11));
		lblValorUnitrio.setBounds(250, 41, 87, 14);
		frame.getContentPane().add(lblValorUnitrio);
		
		lblTotal = new JLabel("Total");
		lblTotal.setFont(new Font("Tahoma", Font.BOLD, 11));
		lblTotal.setBounds(344, 41, 46, 14);
		frame.getContentPane().add(lblTotal);
		
		textQuantQuete = new JTextField();
		textQuantQuete.setColumns(10);
		textQuantQuete.setBounds(195, 93, 41, 20);
		frame.getContentPane().add(textQuantQuete);
		
		textValorQuete = new JTextField();
		textValorQuete.setBackground(UIManager.getColor("Button.background"));
		textValorQuete.setEditable(false);
		textValorQuete.setColumns(10);
		textValorQuete.setBounds(255, 93, 70, 20);
		frame.getContentPane().add(textValorQuete);
		
		textTotal_Quete = new JTextField();
		textTotal_Quete.setBackground(UIManager.getColor("Button.background"));
		textTotal_Quete.setEditable(false);
		textTotal_Quete.setColumns(10);
		textTotal_Quete.setBounds(335, 93, 59, 20);
		frame.getContentPane().add(textTotal_Quete);
		
		textQuantLiche = new JTextField();
		textQuantLiche.setColumns(10);
		textQuantLiche.setBounds(195, 124, 41, 20);
		frame.getContentPane().add(textQuantLiche);
		
		textValorLiche = new JTextField();
		textValorLiche.setBackground(UIManager.getColor("Button.background"));
		textValorLiche.setEditable(false);
		textValorLiche.setColumns(10);
		textValorLiche.setBounds(255, 124, 70, 20);
		frame.getContentPane().add(textValorLiche);
		
		textTotal_Liche = new JTextField();
		textTotal_Liche.setBackground(UIManager.getColor("Button.background"));
		textTotal_Liche.setEditable(false);
		textTotal_Liche.setColumns(10);
		textTotal_Liche.setBounds(335, 122, 59, 20);
		frame.getContentPane().add(textTotal_Liche);
		
		lblBolaDeBasquete = new JLabel("Bola de basquete");
		lblBolaDeBasquete.setBounds(66, 99, 119, 14);
		frame.getContentPane().add(lblBolaDeBasquete);
		
		lblBolaDeBoliche = new JLabel("Bola de boliche");
		lblBolaDeBoliche.setBounds(66, 130, 119, 14);
		frame.getContentPane().add(lblBolaDeBoliche);
		
		textTotal_Total = new JTextField();
		textTotal_Total.setEditable(false);
		textTotal_Total.setColumns(10);
		textTotal_Total.setBounds(335, 153, 59, 20);
		frame.getContentPane().add(textTotal_Total);
		
		final JTextArea txtMensagem = new JTextArea();
		txtMensagem.setWrapStyleWord(true);
		txtMensagem.setFont(new Font("Monospaced", Font.BOLD | Font.ITALIC, 13));
		txtMensagem.setBackground(UIManager.getColor("Button.background"));
		txtMensagem.setLineWrap(true);
		txtMensagem.setEditable(false);
		txtMensagem.setBounds(10, 150, 315, 67);
		frame.getContentPane().add(txtMensagem);
		
		// Valores unitários
		final double gude = 0.20;
		final double quete = 60.00;
		final double liche = 120.00;
			textValorGude.setText(String.valueOf(gude));
			textValorQuete.setText(String.valueOf(quete));
			textValorLiche.setText(String.valueOf(liche));
		
                // iniciar quantidade com 0
		textQuantGude.setText("0");
		textQuantQuete.setText("0");
		textQuantLiche.setText("0");
		
		btnCalculando = new JButton("Calculando");
		btnCalculando.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String nome = textNome.getText();
				int quantGude = Integer.parseInt(textQuantGude.getText()); 
				int quantQuete = Integer.parseInt(textQuantQuete.getText());
				int quantLiche = Integer.parseInt(textQuantLiche.getText());
				
				if ( quantGude <= 0 ) 
					quantGude = 0;
					
				if ( quantQuete <= 0 )
					quantQuete = 0;
				
				if ( quantLiche <= 0 )
					quantLiche = 0;
			
			// total parcial
			double totalGude = quantGude * gude;
			double totalQuete = quantQuete * quete;
			double totalLiche = quantLiche * liche;
				textTotal_Gude.setText("R$ " + totalGude);
				textTotal_Quete.setText("R$ " + totalQuete);
				textTotal_Liche.setText("R$ " + totalLiche);
			
				// total final
			Double total_total = totalGude + totalQuete + totalLiche; 
				textTotal_Total.setText("R$ " + String.valueOf(total_total));
			// mensagem final
			String mensagem = nome + " comprou os itens: ";
			if (quantGude <= 0 && quantQuete <= 0 && quantLiche <= 0){
					mensagem = nome + " Não comprou nenhum dos itens.";
			} else{
					if ( quantGude == 1 )
						mensagem += "Bola de gude, ";
					else if ( quantGude > 1)
						mensagem += "Bolas de gude, ";

					if ( quantQuete == 1 )
						mensagem += "Bola de Basquete, ";
					else if ( quantQuete > 1)
						mensagem += "Bolas de Basquete, ";
			
					if ( quantLiche == 1 )
						mensagem += "Bola de Boliche, ";
					else if ( quantLiche > 1)
						mensagem += "Bolas de Boliche, ";
			}// fim else
			
			// terminar mensagem com  "." final
			int cortar = mensagem.length();
				mensagem = mensagem.substring(0,(cortar - 2));
					mensagem += ".";
						txtMensagem.setText(mensagem);
			}
		});
		btnCalculando.setBounds(215, 7, 110, 23);
		frame.getContentPane().add(btnCalculando);
		
		lblTotal_1 = new JLabel("Total");
		lblTotal_1.setFont(new Font("Tahoma", Font.BOLD, 11));
		lblTotal_1.setBounds(399, 156, 46, 14);
		frame.getContentPane().add(lblTotal_1);
		
		lblR = new JLabel("R$");
		lblR.setFont(new Font("Tahoma", Font.PLAIN, 11));
		lblR.setBounds(238, 62, 19, 20);
		frame.getContentPane().add(lblR);
		
		label = new JLabel("R$");
		label.setFont(new Font("Tahoma", Font.PLAIN, 11));
		label.setBounds(238, 93, 19, 20);
		frame.getContentPane().add(label);
		
		label_1 = new JLabel("R$");
		label_1.setFont(new Font("Tahoma", Font.PLAIN, 11));
		label_1.setBounds(238, 124, 19, 20);
		frame.getContentPane().add(label_1);
	}
}

tiagotgd29, você notou que o número que aparece não é 00000001 e sim 0.6000000000000001, como o numero é grande não está send exibido por inteiro ande com as setas do teclado para ver o número inteiro, não tem nada de errado com seu código, se você fizer:

System.out.println(3 * 0.2);

você irá ter o mesmo resultado a solução para esse calculo é essa mesma, o que acho estranho se descobrir alguma coisa eu postarei, faça o mesmo.
ate+
:smiley:

o problema é como o k_menna disse, quando você multiplica o int 3 por doble 0.2 ele retorna 0.0600001 se voce multiplicar por 6 ele retorna 1.2000002
para voce corrigir isso você pode usar a classe DecimalFormat.
eu corrigi o seu código e agora você vai ver que se você multiplicar por 3 ele ira retornar R$ 0,60.
De uma olhada no código para você entender.
Obs: coloquei os comentários aonde alterei

package Visual; 

  
import java.awt.EventQueue;  
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import javax.swing.*;
  
public class teste {  
  
    private JFrame frame;  
    private JTextField textNome;  
    private JLabel lblBolaDeGude;  
    private JTextField textQuantGude;  
    private JTextField textValorGude;  
    private JTextField textTotal_Gude;  
    private JLabel lblQuant;  
    private JLabel lblValorUnitrio;  
    private JLabel lblTotal;  
    private JTextField textQuantQuete;  
    private JTextField textValorQuete;  
    private JTextField textTotal_Quete;  
    private JTextField textQuantLiche;  
    private JTextField textValorLiche;  
    private JTextField textTotal_Liche;  
    private JLabel lblBolaDeBasquete;  
    private JLabel lblBolaDeBoliche;  
    private JTextField textTotal_Total;  
    private JButton btnCalculando;  
    private JLabel lblTotal_1;  
    private JLabel lblR;  
    private JLabel label;  
    private JLabel label_1; 
    
    //***** aqui instaciei a classe Decimalformat ********
    DecimalFormat formataNr = new DecimalFormat("#,##0.00");  
  
    public static void main(String[] args) {  
        EventQueue.invokeLater(new Runnable() {  
            public void run() {  
                try {  
                    teste window = new teste();  
                    window.frame.setVisible(true);  
                } catch (Exception e) {  
                    e.printStackTrace();  
                }  
            }  
        });  
    }  
    public teste() {  
        initialize();  
    } 
    
   
   // ******metodo que retorna o valor no formato 0,00 ******
    public String retornaValorFormatado(double valor){
        return formataNr.format(valor);
    }
    
    private void initialize() {  
        frame = new JFrame();  
        frame.setBounds(100, 100, 464, 269);  
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
        frame.getContentPane().setLayout(null);  
        frame.setTitle("EXERCICIO 3.2");  
          
        JLabel lblNome = new JLabel("Nome");  
        lblNome.setBounds(10, 11, 46, 14);  
        frame.getContentPane().add(lblNome);  
          
        textNome = new JTextField();  
        textNome.setBounds(66, 8, 139, 20);  
        frame.getContentPane().add(textNome);  
        textNome.setColumns(10);  
          
        JLabel lblItensComprados = new JLabel("Itens comprados");  
        lblItensComprados.setFont(new Font("Tahoma", Font.BOLD, 13));  
        lblItensComprados.setBounds(66, 41, 119, 14);  
        frame.getContentPane().add(lblItensComprados);  
          
        lblBolaDeGude = new JLabel("Bola de gude");  
        lblBolaDeGude.setBounds(66, 68, 119, 14);  
        frame.getContentPane().add(lblBolaDeGude);  
          
        textQuantGude = new JTextField();  
        textQuantGude.setBounds(195, 62, 41, 20);  
        frame.getContentPane().add(textQuantGude);  
        textQuantGude.setColumns(10);  
          
        textValorGude = new JTextField();  
        textValorGude.setBackground(UIManager.getColor("Button.background"));  
        textValorGude.setEditable(false);  
        textValorGude.setBounds(255, 62, 70, 20);  
        frame.getContentPane().add(textValorGude);  
        textValorGude.setColumns(10);  
          
          
        textTotal_Gude = new JTextField();  
        textTotal_Gude.setBackground(UIManager.getColor("Button.background"));  
        textTotal_Gude.setEditable(false);  
        textTotal_Gude.setBounds(335, 62, 80, 20);  
        frame.getContentPane().add(textTotal_Gude);  
        textTotal_Gude.setColumns(10);  
          
        lblQuant = new JLabel("Quant");  
        lblQuant.setFont(new Font("Tahoma", Font.BOLD, 11));  
        lblQuant.setBounds(201, 41, 35, 14);  
        frame.getContentPane().add(lblQuant);  
          
        lblValorUnitrio = new JLabel("Valor Unit\u00E1rio");  
        lblValorUnitrio.setFont(new Font("Tahoma", Font.BOLD, 11));  
        lblValorUnitrio.setBounds(250, 41, 87, 14);  
        frame.getContentPane().add(lblValorUnitrio);  
          
        lblTotal = new JLabel("Total");  
        lblTotal.setFont(new Font("Tahoma", Font.BOLD, 11));  
        lblTotal.setBounds(344, 41, 46, 14);  
        frame.getContentPane().add(lblTotal);  
          
        textQuantQuete = new JTextField();  
        textQuantQuete.setColumns(10);  
        textQuantQuete.setBounds(195, 93, 41, 20);  
        frame.getContentPane().add(textQuantQuete);  
          
        textValorQuete = new JTextField();  
        textValorQuete.setBackground(UIManager.getColor("Button.background"));  
        textValorQuete.setEditable(false);  
        textValorQuete.setColumns(10);  
        textValorQuete.setBounds(255, 93, 70, 20);  
        frame.getContentPane().add(textValorQuete);  
          
        textTotal_Quete = new JTextField();  
        textTotal_Quete.setBackground(UIManager.getColor("Button.background"));  
        textTotal_Quete.setEditable(false);  
        textTotal_Quete.setColumns(10);  
        textTotal_Quete.setBounds(335, 93, 80, 20);  
        frame.getContentPane().add(textTotal_Quete);  
          
        textQuantLiche = new JTextField();  
        textQuantLiche.setColumns(10);  
        textQuantLiche.setBounds(195, 124, 41, 20);  
        frame.getContentPane().add(textQuantLiche);  
          
        textValorLiche = new JTextField();  
        textValorLiche.setBackground(UIManager.getColor("Button.background"));  
        textValorLiche.setEditable(false);  
        textValorLiche.setColumns(10);  
        textValorLiche.setBounds(255, 124, 70, 20);  
        frame.getContentPane().add(textValorLiche);  
          
        textTotal_Liche = new JTextField();  
        textTotal_Liche.setBackground(UIManager.getColor("Button.background"));  
        textTotal_Liche.setEditable(false);  
        textTotal_Liche.setColumns(10);  
        textTotal_Liche.setBounds(335, 122, 80, 20);  
        frame.getContentPane().add(textTotal_Liche);  
          
        lblBolaDeBasquete = new JLabel("Bola de basquete");  
        lblBolaDeBasquete.setBounds(66, 99, 119, 14);  
        frame.getContentPane().add(lblBolaDeBasquete);  
          
        lblBolaDeBoliche = new JLabel("Bola de boliche");  
        lblBolaDeBoliche.setBounds(66, 130, 119, 14);  
        frame.getContentPane().add(lblBolaDeBoliche);  
          
        textTotal_Total = new JTextField();  
        textTotal_Total.setEditable(false);  
        textTotal_Total.setColumns(10);  
        textTotal_Total.setBounds(335, 153, 80, 20);  
        frame.getContentPane().add(textTotal_Total);  
          
        final JTextArea txtMensagem = new JTextArea();  
        txtMensagem.setWrapStyleWord(true);  
        txtMensagem.setFont(new Font("Monospaced", Font.BOLD | Font.ITALIC, 13));  
        txtMensagem.setBackground(UIManager.getColor("Button.background"));  
        txtMensagem.setLineWrap(true);  
        txtMensagem.setEditable(false);  
        txtMensagem.setBounds(10, 150, 315, 67);  
        frame.getContentPane().add(txtMensagem);  
          
        // Valores unitários  
        final double gude = 0.20;  
        final double quete = 60.00;  
        final double liche = 120.00;  
            textValorGude.setText(String.valueOf(gude));  
            textValorQuete.setText(String.valueOf(quete));  
            textValorLiche.setText(String.valueOf(liche));  
          
                // iniciar quantidade com 0  
        textQuantGude.setText("0");  
        textQuantQuete.setText("0");  
        textQuantLiche.setText("0");  
          
        btnCalculando = new JButton("Calculando");  
        btnCalculando.addActionListener(new ActionListener() {  
            public void actionPerformed(ActionEvent arg0) {  
                String nome = textNome.getText();  
                int quantGude = Integer.parseInt(textQuantGude.getText());   
                int quantQuete = Integer.parseInt(textQuantQuete.getText());  
                int quantLiche = Integer.parseInt(textQuantLiche.getText());  
                  
                if ( quantGude <= 0 )   
                    quantGude = 0;  
                      
                if ( quantQuete <= 0 )  
                    quantQuete = 0;  
                  
                if ( quantLiche <= 0 )  
                    quantLiche = 0;  
              
            // total parcial  
            double totalGude = quantGude * gude;  
            double totalQuete = quantQuete * quete;  
            double totalLiche = quantLiche * liche;  
                textTotal_Gude.setText("R$ " + retornaValorFormatado(totalGude));   // ***  aqui voce usa o metodo retornaValorFormatado
                textTotal_Quete.setText("R$ " + retornaValorFormatado(totalQuete)); // ***  aqui voce usa o metodo retornaValorFormatado  
                textTotal_Liche.setText("R$ " + retornaValorFormatado(totalLiche));   // ***  aqui voce usa o metodo retornaValorFormatado
              
                // total final  
            double total_total = totalGude + totalQuete + totalLiche;   
                textTotal_Total.setText("R$ " + retornaValorFormatado(total_total));  // ***  aqui voce usa o metodo retornaValorFormatado
            // mensagem final  
            String mensagem = nome + " comprou os itens: ";  
            if (quantGude <= 0 && quantQuete <= 0 && quantLiche <= 0){  
                    mensagem = nome + " Não comprou nenhum dos itens.";  
            } else{  
                    if ( quantGude == 1 )  
                        mensagem += "Bola de gude, ";  
                    else if ( quantGude > 1)  
                        mensagem += "Bolas de gude, ";  
  
                    if ( quantQuete == 1 )  
                        mensagem += "Bola de Basquete, ";  
                    else if ( quantQuete > 1)  
                        mensagem += "Bolas de Basquete, ";  
              
                    if ( quantLiche == 1 )  
                        mensagem += "Bola de Boliche, ";  
                    else if ( quantLiche > 1)  
                        mensagem += "Bolas de Boliche, ";  
            }// fim else  
              
            // terminar mensagem com  "." final  
            int cortar = mensagem.length();  
                mensagem = mensagem.substring(0,(cortar - 2));  
                    mensagem += ".";  
                        txtMensagem.setText(mensagem);  
            }  
        });  
        btnCalculando.setBounds(215, 7, 110, 23);  
        frame.getContentPane().add(btnCalculando);  
          
        lblTotal_1 = new JLabel("Total");  
        lblTotal_1.setFont(new Font("Tahoma", Font.BOLD, 11));  
        lblTotal_1.setBounds(415, 156, 46, 14);  
        frame.getContentPane().add(lblTotal_1);  
          
        lblR = new JLabel("R$");  
        lblR.setFont(new Font("Tahoma", Font.PLAIN, 11));  
        lblR.setBounds(238, 62, 19, 20);  
        frame.getContentPane().add(lblR);  
          
        label = new JLabel("R$");  
        label.setFont(new Font("Tahoma", Font.PLAIN, 11));  
        label.setBounds(238, 93, 19, 20);  
        frame.getContentPane().add(label);  
          
        label_1 = new JLabel("R$");  
        label_1.setFont(new Font("Tahoma", Font.PLAIN, 11));  
        label_1.setBounds(238, 124, 19, 20);  
        frame.getContentPane().add(label_1);  
    }  
}  

T+

Obrigado k_menna eu não tinha percebido que na tela estava 0.6000000000000001 ; ), então só preciso ajustar as casas decimais como o julianolandim disse.
Já tinha visto alguma coisa de decimal format mais agora ficou mais claro.

Mas uma perguntinha, eu defini 0 como valor inicial nas caixas de quantidade, como eu faço para que quando o usuario aperte TAB a caixa fique selecionada para seja alterado o valor 0 sem precisar apagar o mesmo na mão ??

Teh ++
:slight_smile:

[quote=tiagotgd29]Obrigado k_menna eu não tinha percebido que na tela estava 0.6000000000000001 ; ), então só preciso ajustar as casas decimais como o julianolandim disse.
Já tinha visto alguma coisa de decimal format mais agora ficou mais claro.

Mas uma perguntinha, eu defini 0 como valor inicial nas caixas de quantidade, como eu faço para que quando o usuario aperte TAB a caixa fique selecionada para seja alterado o valor 0 sem precisar apagar o mesmo na mão ??

Teh ++
:)[/quote]
quando o campo receber o foco coloca isso

 seuCampo.setSelectionStart(0);
 seuCampo.setSelectionEnd(seuCampo.getText().length());

Obrigado galera por ajudar nesse meu primeiro tópico, mais alguns conhecimentos um dia eu chego lá rsss.
Vou colocar o tópico como resolvido.
:wink:

Sem problemas precisando :smiley: