Galera, comecei Java ontem e não to conseguindo fazer ações nos TextField’s …
quero que quando eu apertar enter passe uma mensagem na tela dizendo o conteudo do botão, vejam:
import java.awt.*;
import javax.swing.*;
public class LabelFrame extends JFrame
{
private JLabel label1;
private JTextField textField1;
private JPasswordField password1;
private JTextArea Tarea1;
public LabelFrame()
{
super( "Titulo" );
setLayout( new FlowLayout() );
label1 = new JLabel( "Label with text" );
label1.setToolTipText( "This is label1" );
add( label1 );
textField1 = new JTextField( "aaaaaa", 10);
add( textField1 );
password1 = new JPasswordField( "sua senha", 10);
add( password1 );
Tarea1 = new JTextArea( "TeStE", 10, 20);
add( Tarea1 );
TextFieldHandler handler = new TextFieldHandler();
textField1.addActionListener( handler );
}
private class TextFieldHandler implements ActionListener
{
public void actionPerformed( ActionEvent event )
{
String string = "";
if (event.getSource() == textField1)
string = String.format( "textField1: %s",
event.getActionCommand());
JOptionPane.showMessageDialog( null, string );
}
}
}
Onde esta o erro ??? parece estar tudo certo para mim …
[size=“11”]
[color=“red”]
- Editado: Lembre-se de usar BBCode em seus códigos para mantê-los identados e mais legíveis para outros usuários - Matheus[/color][/size] :joia: