Erro no código!

2 respostas
T

Primeiramente gostaria de parabenizar o site com ênfase nesse grande FORUM,aprendi muito aqui já!!!

Minha dúvida é nesse programa,pois ao compilar ele não gera nenhum erro porém a execução está travando!!!Estou trabalhando com a parte gráfica do java,butão,label,etc.

Aí vai o códigopra facilitar:

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;



public class PintaJanela{
	public static void main(String args[]){
		
		JFrame frame = new Janela(700,100);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}
	
	
}




class Janela extends JFrame{
	
	JPanel content;
	JTextField field,field2;
	JButton button;
	
	public Janela(int height,int width){
		
		this.setTitle("Jogo da Adivinhação");
		
		content = new JPanel();
		content.setLayout(new FlowLayout(FlowLayout.LEFT));
		content.setBackground(Color.gray);
		
		
		JLabel label = new JLabel("ENTRE COM UM VALOR ENTRE 1 E 10");
		label.setFont(new Font("SERIF",Font.ITALIC,15));
		label.setForeground(Color.white);
		content.add(label);
		
		field = new JTextField(6);
		content.add(field);
		
		button = new JButton("CLIQUE");
		button.setForeground(Color.white);
		button.addActionListener(new Adivinha());		
		content.add(button);
		
		field2 = new JTextField(20);
		content.add(field2);
		field2.setEditable(false);	
		
		
		
		this.setContentPane(content);
		this.setSize(height,width);
		this.validate();
		
		
	}
	
	
	
	class Adivinha implements ActionListener{
		
		
		public String sai = "false";
		
		public void actionPerformed(ActionEvent e){
			
			//public String sai = "false";
			
			int valor = 1 + (int)(Math.random() * 10);
			
			
			do{		
			   int aux = Integer.parseInt(field.getText());	
			   
			   if(aux > valor){
				   content.setBackground(Color.red);
				   field2.setText("Tente um valor MENOR");				
				   
				
			   }else if(aux < valor){
				   content.setBackground(Color.blue);
				   field2.setText("Tente um valor MAIOR");
				   
			   }else{
				   field2.setText("VOCE ACERTOU...PARABENS!!!");
				   sai = "true";
			   }
			}while(sai.equals("false"));
			
			
			
		}//fim do metodo actionPerformed
		
		
	
			
	}//fim da classe Adivinha
	
	
	
	
	
}//fim da classe Janela

2 Respostas

F

da erro aqui

java.lang.NoClassDefFoundError: aplicacaoteste/PintaJanela
Exception in thread “main”
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

de uma olhada

B

tira o do{} while … vai funcionar !

Criado 1 de junho de 2005
Ultima resposta 1 de jun. de 2005
Respostas 2
Participantes 3