Caja de texto actualizable
Publicado por josejorr (1 intervención) el 17/04/2009 14:28:02
Necesito que el texto de una caja de texto se vaya actualizando en funcion de un bucle for.
El problema es que me presenta solo la informacion del ultimo valor que toma la variable del for en este caso el 5, me podrian decir como podria hacerlo?
public PruebaEtiqueta()
{
super( "Prueba de JLabel" );
// obtener panel de contenido y establecer su esquema
Container contenedor = getContentPane();
contenedor.setLayout( new FlowLayout() );
// constructor de JLabel con un argumento cadena, constructor de TextField ( Campo de Texto)
etiqueta = new JLabel( "Etiqueta con texto");
etiqueta.setToolTipText( "Esta es la etiqueta");
etiqueta.setText("TELEFONO:");
contenedor.add( etiqueta );
TextField telefono;
telefono= new TextField();
contenedor.add( telefono );
// Declaracion de variables
String telefono1 = new String( "111111111" );
String telefono2 = new String( "222222222" );
String telefono3 = new String( "333333333" );
String telefono4 = new String( "444444444" );
String telefono5 = new String( "555555555" );
for(int i=1; i<=5; i++) {
String tel = new String ("telefono"+Integer.toString(i));
Integer num = new Integer(tel);
String numero = new String (Integer.toString(num));
telefono.setText(numero);
}
setSize( 400, 170 ); // define tamaño ventana.
setVisible( true ); // Propiedad ventana visible.
}
// Fin Del Metodo PruebaEtiqueta
// fin del constructor
Gracias.
El problema es que me presenta solo la informacion del ultimo valor que toma la variable del for en este caso el 5, me podrian decir como podria hacerlo?
public PruebaEtiqueta()
{
super( "Prueba de JLabel" );
// obtener panel de contenido y establecer su esquema
Container contenedor = getContentPane();
contenedor.setLayout( new FlowLayout() );
// constructor de JLabel con un argumento cadena, constructor de TextField ( Campo de Texto)
etiqueta = new JLabel( "Etiqueta con texto");
etiqueta.setToolTipText( "Esta es la etiqueta");
etiqueta.setText("TELEFONO:");
contenedor.add( etiqueta );
TextField telefono;
telefono= new TextField();
contenedor.add( telefono );
// Declaracion de variables
String telefono1 = new String( "111111111" );
String telefono2 = new String( "222222222" );
String telefono3 = new String( "333333333" );
String telefono4 = new String( "444444444" );
String telefono5 = new String( "555555555" );
for(int i=1; i<=5; i++) {
String tel = new String ("telefono"+Integer.toString(i));
Integer num = new Integer(tel);
String numero = new String (Integer.toString(num));
telefono.setText(numero);
}
setSize( 400, 170 ); // define tamaño ventana.
setVisible( true ); // Propiedad ventana visible.
}
// Fin Del Metodo PruebaEtiqueta
// fin del constructor
Gracias.
Valora esta pregunta


0