Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/02/2011, 15:52
Avatar de Pafate
Pafate
 
Fecha de Ingreso: mayo-2010
Mensajes: 232
Antigüedad: 14 años
Puntos: 1
Comparar 2 jtextfield

Hola no puedo comparar los jtextfield.
intente pasarlos a string
Código:
String asd = (t.getText());
Pero tampoco funciono.

Código:
package jfram;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Venta extends JFrame
{
    
     /** La ventana */
    private JFrame v;
    
    /** El botón */
    private JButton b;
    private JTextField s;
    private JTextField t;
    private JTextField f;
    private JTextField c;
    public Venta()
    {      
        
        v = new JFrame("Ventana Hola Mundo");
        v.getContentPane().setLayout(new FlowLayout());
        b = new JButton("Aceptar");
        v.getContentPane().add (b);      
        t = new JTextField(20);
        v.getContentPane().add(t);
        c = new JTextField(20);
        v.getContentPane().add(c);
        f = new JTextField(20);
        v.getContentPane().add(f);
         s = new JTextField(20); <--- Esto no deberia ser un textfield, pero nose como agregar texto si no es con textfield :porra:
        v.getContentPane().add(s);       
        s.setText("Ingresar algo");
         b.addActionListener(new ActionListener()
        {
        	public void actionPerformed(ActionEvent e)
        	{
                    
                f.setText(t.getText()); <-- Pongo que F guarde el texto de T
                
                if(t.equals(f)){             <-- Me fijo si T es Igual a F(deberia ya que lo puse arriba, pero no... me toma como incorrecto)
        c.setText("Correcto!");
        }else{
        c.setText("La respuesta correcta era dos");
        }
        	}
        });
        v.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        v.setSize(400,500);        
        // Se hace visible la ventana
        v.setVisible(true);
            	       }         

}
PD: Como agrego texto sin que sea textfield?