Ver Mensaje Individual
  #6 (permalink)  
Antiguo 02/03/2011, 18:37
yuo2
 
Fecha de Ingreso: diciembre-2008
Ubicación: PERU
Mensajes: 294
Antigüedad: 15 años, 4 meses
Puntos: 23
Respuesta: ejecutar un metodo en java..?

Q' falta??

No veo ningun error (uso eclipse) en codigo... pero no me suma. Me estara faltando algo ??

Porfa nesecito hacer este ejemplo sencillo de suma pero usando clases y metodos. Bueno aqui mi codigo ya correjido pero no me lanza el resultado.

alumno.java
Código Javascript:
Ver original
  1. package src;
  2.  
  3. import java.awt.event.*;
  4.  
  5. public class alumno {
  6.     public String alu_cod;
  7.     public String alu_nomb;
  8.     public String alu_ape;
  9.     public String alu_nota1;
  10.     public String alu_nota2;
  11.     public Integer alu_prom;   
  12.  
  13.      
  14.     class Nota implements ActionListener{
  15.  
  16.         public void actionPerformed (ActionEvent evento){
  17.             alu_prom = Integer.parseInt(alu_nota1)+ Integer.parseInt(alu_nota2);
  18.            
  19.             //System.out.println(alu_prom);            
  20.             }  
  21.         }
  22.    
  23. }

falumno.java

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