Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/03/2011, 01:30
yuo2
 
Fecha de Ingreso: diciembre-2008
Ubicación: PERU
Mensajes: 294
Antigüedad: 15 años, 4 meses
Puntos: 23
JTextField.getText() no me captura

En falumno.java
En esta parte cuando pruebo con:
mialumno.alu_nota1 = "3";
mialumno.alu_nota2 = "5";

me da el resultado, todo OK...

Pero cuando utilizo el getText(), no me resuelve la operacion
mialumno.alu_nota1 = txt1.getText();
mialumno.alu_nota2 = txt2.getText();




falumno.java
Código Javascript:
Ver original
  1. package src;
  2.  
  3. import javax.swing.JButton;
  4. import javax.swing.JFrame;
  5. import javax.swing.JTextField;
  6.  
  7. import src.alumno.Nota;
  8.  
  9.  
  10. public class falumno {
  11.  
  12.     public JFrame falu;
  13.     public JButton btcal;
  14.     public JTextField txt1, txt2, txt3;
  15.  
  16.     public falumno(){
  17.         falu = new JFrame("prueba");
  18.         falu.setSize(400,300);
  19.         falu.setLocation(300,300);
  20.         falu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  21.         falu.getContentPane().setLayout(null);
  22.        
  23.        
  24.         btcal = new JButton("Calcula");
  25.         btcal.setSize(90,30);
  26.         btcal.setLocation(150,200);
  27.        
  28.        
  29.         txt1 = new JTextField("");
  30.         txt1.setLocation(150,50);
  31.         txt1.setSize(90,30);
  32.                    
  33.         txt2 = new JTextField("");
  34.         txt2.setLocation(150,90);
  35.         txt2.setSize(90,30);
  36.        
  37.         txt3 = new JTextField();
  38.         txt3.setLocation(150,150);
  39.         txt3.setSize(90,30);
  40.        
  41.         alumno mialumno = new alumno();
  42.         /*mialumno.alu_nota1 = "3";
  43.         mialumno.alu_nota2 = "5";*/
  44.        
  45.         mialumno.alu_nota1 = txt1.getText();
  46.         mialumno.alu_nota2 = txt2.getText();
  47.        
  48.         Nota minota = mialumno.new Nota();
  49.         btcal.addActionListener(minota);
  50.         //txt3.setText(minota.promedio);
  51.        
  52.        
  53.         falu.getContentPane().add(txt1);
  54.         falu.getContentPane().add(txt2);
  55.         falu.getContentPane().add(txt3);
  56.         falu.getContentPane().add(btcal);
  57.         falu.setVisible(true);
  58.     }
  59.    
  60.     public static void main(String[] args){
  61.         falumno ventana = new falumno();               
  62.     }
  63.  
  64. }

alumno.java
Código Javascript:
Ver original
  1. package src;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4.  
  5.  
  6. public class alumno {
  7.     public String alu_cod;
  8.     public String alu_nomb;
  9.     public String alu_ape;
  10.     public String alu_nota1;
  11.     public String alu_nota2;
  12.     public Integer alu_prom;   
  13.    
  14.  
  15.      
  16.     class Nota implements ActionListener{
  17.         String promedio; {}
  18.            
  19.            
  20.         public void actionPerformed (ActionEvent e){
  21.             try{
  22.                
  23.             alu_prom =  Integer.parseInt(alu_nota1) + Integer.parseInt(alu_nota2);         
  24.             promedio = Integer.toString(alu_prom); 
  25.             System.out.println(promedio);
  26.            
  27.             }catch(Exception x){
  28.                 System.out.println("no hay valores");
  29.  
  30.             }      
  31.         }
  32.     }
  33.            
  34.    
  35. }