Ajuda

caros amigos me ajudema identificar onde esta meu erro, sou iniciante neste assunto de programação em java, mais estou tentando aprender…

import java.awt.;
import java.awt.event.
;
import javax.swing.*;
public class Exemplo3 extends JFrame
{

String texto;

private JTextField Tfield1, Tfield2,Tfield3;
private JLabel Lbl1,Lbl2,Lbl3;

public <TextFieldTratar> Exemplo3()
{
	super("Utilizando JTextField");
	Container c = getContentPane();
	c.setLayout(new GridLayout(3,2));  //3 colunas ,2linhas
	
	
	//Label (titulos) para campos de textos
	Lbl1 = new JLabel("Digite um texto aqui:",SwingConstants.RIGHT);	
	Lbl2 =new JLabel("Este já vem com o texto",SwingConstants.RIGHT);
	Lbl3 =new JLabel("Este naum pode ser editado",SwingConstants.RIGHT);
	
	Tfield1 =new JTextField(20);
	Tfield2 = new JTextField("Campo texto preenchido e editavel",20);
	
	Tfield3 = new JTextField("campo texto nuam editavel",20);
	
	Tfield3.setEditable(false);
	c.add(Lbl1);
	c.add(Tfield1);
	
	c.add(Lbl2);
	c.add(Tfield2);
	
	c.add(Lbl3);
	c.add(Tfield3);
	
	TextFieldTratar tratarTF = new TextFieldTratar();     //linha 39
	
	Tfield1.addActionListener(tratarTF);
	Tfield2.addActionListener(tratarTF);
	Tfield3.addActionListener(tratarTF);
	
	setSize(420,120);
	show();
	
}

public static void main(String[] args) 

{
	Exemplo3 app= new Exemplo3();   //linha 53
	app.addWindowListener(new WindowAdapter()[color=blue] [/color]
	{
		public void windowClosing(WindowEvent e)
		{
			System.exit(0);
		}

	
	});
	
}
	
	
private class TextFieldTratar implements ActionListener
{
	
	public void actionPerformed(ActionEvent e)
	{
			texto="";
			
			if(e.getSource()== Tfield1)
				texto="conteudo de Tfield1="+Tfield1.getText(); // retorno do texto
			else if (e.getSource()==Tfield2)
				texto = "conteudo do Tfield2="+Tfield2.getText();
			else if (e.getSource()==Tfield3)
				texto = "conteudo do Tfield3="+Tfield3.getText();
			
			JOptionPane.showMessageDialog(null,texto,"texto digitado",JOptionPane.WARNING_MESSAGE);
			
			
	}

}

}

na hora de compilar da o seguinte erro:

The method addActionListener(ActionListener) in the type JTextField is not applicable for the arguments (TextFieldTratar)
The method addActionListener(ActionListener) in the type JTextField is not applicable for the arguments (TextFieldTratar)

at Exemplo3.<init>(Exemplo3.java:39)
at Exemplo3.main(Exemplo3.java:53)

Oi,

Da proxima vez use a tag code,para postar seu codigo… :wink:

[code]

import java.awt.;
import java.awt.event.
;
import javax.swing.*;
public class Exemplo3 extends JFrame
{

String texto;

private JTextField Tfield1, Tfield2,Tfield3;
private JLabel Lbl1,Lbl2,Lbl3;

public Exemplo3()
{
super(“Utilizando JTextField”);
Container c = getContentPane();
c.setLayout(new GridLayout(3,2)); //3 colunas ,2linhas

//Label (titulos) para campos de textos
Lbl1 = new JLabel(“Digite um texto aqui:”,SwingConstants.RIGHT);
Lbl2 =new JLabel(“Este já vem com o texto”,SwingConstants.RIGHT);
Lbl3 =new JLabel(“Este naum pode ser editado”,SwingConstants.RIGHT);

Tfield1 =new JTextField(20);
Tfield2 = new JTextField(“Campo texto preenchido e editavel”,20);

Tfield3 = new JTextField(“campo texto nuam editavel”,20);

Tfield3.setEditable(false);
c.add(Lbl1);
c.add(Tfield1);

c.add(Lbl2);
c.add(Tfield2);

c.add(Lbl3);
c.add(Tfield3);

TextFieldTratar tratarTF = new TextFieldTratar(); //linha 39

Tfield1.addActionListener(tratarTF);
Tfield2.addActionListener(tratarTF);
Tfield3.addActionListener(tratarTF);

setSize(420,120);
show();

}

public static void main(String[] args)

{
Exemplo3 app= new Exemplo3(); //linha 53
app.addWindowListener(new WindowAdapter()[color=blue] [/color]
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}

});

}

private class TextFieldTratar implements ActionListener
{

public void actionPerformed(ActionEvent e)
{
texto="";

if(e.getSource()== Tfield1)
texto=“conteudo de Tfield1=”+Tfield1.getText(); // retorno do texto
else if (e.getSource()==Tfield2)
texto = “conteudo do Tfield2=”+Tfield2.getText();
else if (e.getSource()==Tfield3)
texto = “conteudo do Tfield3=”+Tfield3.getText();

JOptionPane.showMessageDialog(null,texto,“texto digitado”,JOptionPane.WARNING_MESSAGE);

}

}

} [/code]

Boa sorte!

brigadu pela ajuda… vlw

Por nada… :stuck_out_tongue:

Acho que o problema no seu código está nesse trecho…


public <TextFieldTratar> Exemplo3()   {  
 super("Utilizando JTextField");  

Da uma olhadinha aqui >> http://www.vivaolinux.com.br/artigo/Java-Usando-JInternalFrame-de-forma-elegante?pagina=3

Boa sorte!

Cara, também sou novo em java, e não sei pra que essas coisas ali >> mas tirando o pra ficar um construtor normal e [color = blue][/ color] o código roda normalmente… pq com ele não reconhece como uma classe na hora da instância…
flw \m/ 8)

ah e uma dica, usa setVisible(true) xD o show é obsoleto…

Favor mudar o titulo do tópico para ficar mais claro para os outros usuários.