Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/05/2011, 17:34
Avatar de davidmiichu
davidmiichu
 
Fecha de Ingreso: mayo-2011
Mensajes: 21
Antigüedad: 13 años
Puntos: 0
aiuda con este Codigo JTextFiled

Hola amigos, disculpen si puse "aiuda" se q es "ayuda" pero no podia ponerlo como titulo, bueno tengo qe crear un programa en donde capture dos valores en dos JTEXTFIELDS y q pulsando un boton de el resultado... yo tengo el sgte codigo.. pero no se como capturar los valores digitados en el TEXTFIELD.....

CLASE PRINCIPAL


Código Javascript:
Ver original
  1. import java.awt.event.ActionListener;
  2.  
  3. import javax.swing.JButton;
  4. import javax.swing.JFrame;
  5. import javax.swing.JLabel;
  6. import javax.swing.JPanel;
  7. import javax.swing.JTextField;
  8.  
  9.      public class ventana extends JFrame {
  10.    
  11.          public ventana (){
  12.              
  13.              //nombre de la ventana//
  14.      
  15.              JFrame v= new JFrame("Calcular");
  16.             v.setVisible(true);
  17.            
  18.             //propiedades de la ventana//
  19.              
  20.             JPanel Ventana =new JPanel ();
  21.             Ventana.setLayout(null);
  22.             Ventana.setBounds(300, 400, 500, 300);
  23.             Ventana.setVisible(true);
  24.            
  25.             //primer Label //
  26.            
  27.             JLabel a=new JLabel("Digita el valor 1");
  28.             a.setBounds(100,10,150,20);
  29.             Ventana.add(a);
  30.             v.add(Ventana);
  31.             v.setBounds(300,400,500,300);
  32.            
  33.             //Text Field para el primer label //
  34.            
  35.             JTextField txta = new JTextField();
  36.             txta.setBounds(200,10,150,20);
  37.             txta.setVisible(true);
  38.             Ventana.add(txta);
  39.             String x = txta.getText();
  40.            
  41.            
  42.            
  43.             JTextField txt = new JTextField ();
  44.             txt.setBounds(10,10,150,20);
  45.             txt.setVisible(true);
  46.             Ventana.add(txt);
  47.             txt.setText(a.getText());
  48.            
  49.             //segundo Label //
  50.            
  51.             JLabel b = new JLabel ("Digita el valor 2");
  52.             b.setBounds(100,40,150,20);
  53.             Ventana.add(b);
  54.             v.add(Ventana);
  55.             v.setBounds(300,400,500,300);
  56.            
  57.             //Segundo text field para el label //
  58.            
  59.             JTextField txtb = new JTextField ();
  60.             txtb.setBounds(200,40,150,20);
  61.             txtb.setVisible(true);
  62.             Ventana.add(txtb);
  63.            
  64.                    
  65.             // Boton de calcular //
  66.            
  67.             JButton boton1 = new JButton("Calcular");
  68.             boton1.setBounds(200, 160, 100, 20);
  69.             Ventana.add(boton1);
  70.             Oprima men = new Oprima ();    ///<<< Funcion para el boton //
  71.             boton1.addActionListener(men);    ///<<< Funcion para el boton //
  72.            
  73.            
  74.            
  75.            
  76.  
  77.         }
  78.  
  79.        
  80.            
  81.        
  82.      }

CLASE DEL BOTON


Código Javascript:
Ver original
  1. import java.awt.event.ActionEvent;
  2. import java.awt.event.ActionListener;
  3.  
  4. import javax.swing.JOptionPane;
  5.  
  6.  
  7. class Oprima implements ActionListener {
  8. public void actionPerformed(ActionEvent e) {
  9.    
  10.    
  11.     //<< recibe y hace la funcion apra el boton ///
  12.     JOptionPane.showMessageDialog(null, "hola" );      //<< recibe y hace la funcion apra el boton ///
  13.  
  14.  
  15. }
  16. }



ayuda por favor