Retroceder   Foros del Web > Programación para sitios web > Java y JSP

Respuesta
 
Herramientas Desplegado
Antiguo 25-sep-2006, 12:29   #1 (permalink)
mveraa ha deshabilitado el karma
 
Avatar de mveraa
 
Fecha de Ingreso: diciembre-2002
Ubicación: santiago-chilito
Mensajes: 1.766
Enviar un mensaje por MSN a mveraa
ayuda para este novato con textfield

hola maestros tengo este codigo en donde aprendo de apocos java , necesecito aprender a llenar una caja de texto. pero no me funciona , no me sale el cursor en la caja de texto para ingresar valores.
¿alguien me puede orientar?

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

public class cinco
{
public static void main(String[] args)
{
JFrame frame=new JFrame();
JButton boton=new JButton("Un botó");
JTextField text=new JTextField();

frame.getContentPane().setLayout(new BorderLayout());
frame.add(boton, BorderLayout.SOUTH);
frame.add(text, BorderLayout.NORTH);




//escucha boton
boton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.out.println("me apretaron");

}
});


text.addKeyListener(new java.awt.event.KeyAdapter()
{
public void keyPressed(KeyEvent e)
{
text.setText(e.getKeyChar() );

}
});






frame.pack();
frame.setVisible(true);




}





}


un saludo
__________________
"Cuando se adelanta un oponente, enfréntalo y salúdalo; si intenta retroceder, déjalo seguir su camino"
mveraa está desconectado   Responder Citando
Antiguo 25-sep-2006, 12:36   #2 (permalink)
mveraa ha deshabilitado el karma
 
Avatar de mveraa
 
Fecha de Ingreso: diciembre-2002
Ubicación: santiago-chilito
Mensajes: 1.766
Enviar un mensaje por MSN a mveraa
me marca estos errores.

1. ERROR in cinco.java
(at line 43)
text.setText(e.getKeyChar() );
^^^^
Cannot refer to a non-final variable text inside an inner class defined in a different method
----------
2. ERROR in cinco.java
(at line 43)
text.setText(e.getKeyChar() );
^^^^^^^
The method setText(String) in the type JTextComponent is not applicable for the arguments (char)
__________________
"Cuando se adelanta un oponente, enfréntalo y salúdalo; si intenta retroceder, déjalo seguir su camino"
mveraa está desconectado   Responder Citando
Antiguo 25-sep-2006, 13:45   #3 (permalink)
eledil ha deshabilitado el karma
 
Fecha de Ingreso: septiembre-2005
Mensajes: 30
De acuerdo

mmm bueno no soy tan bueno n java pero creo q el primer error q te da te dice q JTextField en este caso debe ser estar declarado como final, y el segundo te dice que l metodo de Jtext ".setText(String)" debe recibir como parametro un String y tu le estabas mandando un "char"...espero q te sirva, ...salu2

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class prueba
{
public static void main(String[] args)
{
JFrame frame=new JFrame();
final JButton boton=new JButton("Un botó");
final JTextField text=new JTextField();

frame.getContentPane().setLayout(new BorderLayout());
frame.add(boton, BorderLayout.SOUTH);
frame.add(text, BorderLayout.NORTH);
//escucha boton
boton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
text.setText("Me apretaron!!");
}
});
frame.pack();
frame.setVisible(true);
}
}
eledil está desconectado   Responder Citando
Antiguo 25-sep-2006, 14:32   #4 (permalink)
mveraa ha deshabilitado el karma
 
Avatar de mveraa
 
Fecha de Ingreso: diciembre-2002
Ubicación: santiago-chilito
Mensajes: 1.766
Enviar un mensaje por MSN a mveraa
gracias por tu ayuda
__________________
"Cuando se adelanta un oponente, enfréntalo y salúdalo; si intenta retroceder, déjalo seguir su camino"
mveraa está desconectado   Responder Citando
Respuesta

No hay votos aún.


Herramientas
Desplegado

Normas de Publicación
No puedes crear nuevos temas
No puedes responder temas
No puedes subir archivos adjuntos
No puedes editar tus mensajes

BB code is Activado
Caritas están Activado
[IMG] está Desactivado
Código HTML está Desactivado


La Zona horaria es GMT -6. Ahora son las 13:26.


Message Board Statistics

LinkBacks Enabled by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93