2

He creado un formulario en java con NetBeans un JFrame (Principal), Dialog(Matricula), Clase Estudiante, Clase GestorEstudiante. En Matricula tengo 2 combobox una para el ciclo y otra para el curso, dependendiendo de eso se llena el txtcredito(Credito) y txtcostocredito(CostoCredito) segun la tabla:

introducir la descripción de la imagen aquí

Este es el formulario:

introducir la descripción de la imagen aquí

He realizado la programacion para el boton calcular (credito*costocredito)=montomatricula. y el boton resumir que te muestra todos los datos ingresados (Nombre,Apellidos,Ciclo,etc).

También realice la condicional con los combobox para llenar el textbox pero no me lo muestra. Ahi requiero su apoyo. les pongo el codigo para que me ayuden.

FrmCalculaMatricula (JDialog)

    import javax.swing.JOptionPane;

    public class FrmCalculaMatricula extends javax.swing.JDialog
    {
private GestorEstudiante estudiantes;
private Estudiante estudiante;

public GestorEstudiante getEstudiante() {
    return estudiantes;
}

public void setEstudiantes(GestorEstudiante estudiante) {
    this.estudiantes = estudiante;
}

/**
 * Creates new form FrmCalculaMatricula
 */
public FrmCalculaMatricula(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
}

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

    jPanel1 = new javax.swing.JPanel();
    jScrollPane1 = new javax.swing.JScrollPane();
    txtResumen = new javax.swing.JTextArea();
    lblCreditos = new javax.swing.JLabel();
    btnSalir = new javax.swing.JButton();
    lblCostoCredito = new javax.swing.JLabel();
    lblMontoMatricula = new javax.swing.JLabel();
    txtCreditos = new javax.swing.JTextField();
    lblMatriculaA = new javax.swing.JLabel();
    lblResumenMatricula = new javax.swing.JLabel();
    txtMontoMatricula = new javax.swing.JTextField();
    txtCostoCredito = new javax.swing.JTextField();
    cboCiclo = new javax.swing.JComboBox();
    jSeparator1 = new javax.swing.JSeparator();
    btnCalcular = new javax.swing.JButton();
    txtApellido = new javax.swing.JTextField();
    lblCurso = new javax.swing.JLabel();
    lblNombre = new javax.swing.JLabel();
    lblApellido = new javax.swing.JLabel();
    cboCurso = new javax.swing.JComboBox();
    lblCiclo = new javax.swing.JLabel();
    txtNombre = new javax.swing.JTextField();
    lblDatoAlumno = new javax.swing.JLabel();
    btnResumir = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setTitle("Calcular Matricula");

    jPanel1.setToolTipText("");
    jPanel1.setName("");

    txtResumen.setColumns(20);
    txtResumen.setEditable(false);
    txtResumen.setRows(5);
    jScrollPane1.setViewportView(txtResumen);

    lblCreditos.setText("Créditos");

    btnSalir.setText("Salir");
    btnSalir.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnSalirActionPerformed(evt);
        }
    });

    lblCostoCredito.setText("Costo-Credito");

    lblMontoMatricula.setText("Monto de Matrícula");

    txtCreditos.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
    txtCreditos.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            txtCreditosActionPerformed(evt);
        }
    });

    lblMatriculaA.setText("Matricula Alumno");

    lblResumenMatricula.setText("Resumen de la Matricula");

    txtCostoCredito.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            txtCostoCreditoActionPerformed(evt);
        }
    });

    cboCiclo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X" }));
    cboCiclo.setSelectedItem(cboCiclo);
    cboCiclo.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            cboCicloActionPerformed(evt);
        }
    });

    btnCalcular.setText("Calcular");
    btnCalcular.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnCalcularActionPerformed(evt);
        }
    });

    lblCurso.setText("Curso");

    lblNombre.setText("Nombre");

    lblApellido.setText("Apellido");

    cboCurso.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Curso A", "Curso B", "Curso C" }));

    lblCiclo.setText("Ciclo");

    txtNombre.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            txtNombreActionPerformed(evt);
        }
    });

    lblDatoAlumno.setText("Datos del Alumno");

    btnResumir.setText("Resumir");
    btnResumir.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnResumirActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(170, 170, 170)
                    .addComponent(lblMatriculaA))
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(21, 21, 21)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(lblDatoAlumno)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(lblNombre)
                            .addGap(18, 18, 18)
                            .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGap(38, 38, 38)
                    .addComponent(lblApellido)
                    .addGap(18, 18, 18)
                    .addComponent(txtApellido, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 458, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(17, 17, 17)
                    .addComponent(lblCiclo)
                    .addGap(18, 18, 18)
                    .addComponent(cboCiclo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(29, 29, 29)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(lblCurso)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cboCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(btnResumir)
                                .addGap(11, 11, 11)))
                        .addComponent(btnCalcular, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(32, 32, 32)
                            .addComponent(lblCreditos)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(txtCreditos, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addComponent(lblCostoCredito)
                            .addGap(18, 18, 18)
                            .addComponent(txtCostoCredito, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(18, 18, 18)
                            .addComponent(lblMontoMatricula)
                            .addGap(18, 18, 18)
                            .addComponent(txtMontoMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(lblResumenMatricula)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 291, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(108, 108, 108)))
            .addContainerGap(40, Short.MAX_VALUE))
    );
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(lblDatoAlumno)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(lblNombre)
                .addComponent(lblApellido)
                .addComponent(txtApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(18, 18, 18)
            .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(lblMatriculaA)
            .addGap(18, 18, 18)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(lblCiclo)
                .addComponent(cboCiclo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(lblCurso)
                .addComponent(cboCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(lblCreditos)
                .addComponent(txtCreditos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(lblCostoCredito)
                .addComponent(txtCostoCredito, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(65, 65, 65)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(btnCalcular)
                        .addComponent(txtMontoMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblMontoMatricula))
                    .addGap(38, 38, 38)
                    .addComponent(lblResumenMatricula)
                    .addGap(18, 18, 18)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(35, 35, 35)
                    .addComponent(btnSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(189, 189, 189)
                    .addComponent(btnResumir)))
            .addContainerGap())
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(0, 0, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );

    pack();
}// </editor-fold>

private void txtNombreActionPerformed(java.awt.event.ActionEvent evt) {                                          
    // TODO add your handling code here:
}                                         

private void cboCicloActionPerformed(java.awt.event.ActionEvent evt) {                                         

}                                        

private void btnResumirActionPerformed(java.awt.event.ActionEvent evt) {                                           

    this.txtResumen.setText( "Datos del Alumno "+ "  Nombres: "+ txtNombre.getText()
            +" Apellidos "+txtApellido.getText()+" Ciclo:  "+ cboCiclo.getSelectedItem()+" Curso: "+
            cboCurso.getSelectedItem()+" Credito: "+ txtCreditos.getText()+
            " Costo Credito: "+ txtCostoCredito.getText()+
            " Monto a Pagar Matricula: "+ txtMontoMatricula.getText());
   this.txtResumen.setLineWrap(true);
   this.txtResumen.setWrapStyleWord(true);
}                                          

private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {                                         
    this.dispose();
}                                        

private void txtCreditosActionPerformed(java.awt.event.ActionEvent evt) {                                            

    int opCiclo = this.cboCiclo.getSelectedIndex();
    int opCurso = this.cboCurso.getSelectedIndex();
    float cred;

    if (opCiclo==0 || opCiclo==1 || opCiclo==2)
    {
        switch(opCurso)
        {
            case 0:
                cred=0;
                this.txtCreditos.setText(""+cred);
                break;
            case 1:
                cred=4;
                this.txtCreditos.setText(""+cred);
                break;
            default:
                cred=3;
                this.txtCreditos.setText(""+cred);                 
                break;
        }
    }
    else if (opCiclo==3 || opCiclo==4 || opCiclo==5)
    {
        switch(opCurso)
        {
            case 0:
                cred=4;                    
                this.txtCreditos.setText(""+cred);                 
                break;
            case 1:
                cred=3;                    
                this.txtCreditos.setText(""+cred);                 
                break;
            default:
                cred=6;                    
                this.txtCreditos.setText(""+cred);                 
                break;
        }
    }
    else
    {
        switch(opCurso)
        {
            case 0:
                cred=3;                    
                this.txtCreditos.setText(""+cred);                 
                break;
            case 1:
                cred=4;                    
                this.txtCreditos.setText(""+cred);                 
                break;
            default:
                cred=5;                    
                this.txtCreditos.setText(""+cred);                 
                break;
        }
    }        
}                                           

private void txtCostoCreditoActionPerformed(java.awt.event.ActionEvent evt) {                                               
    int opCiclo = this.cboCiclo.getSelectedIndex();
    int opCurso = this.cboCurso.getSelectedIndex();
    float cred;

    if (opCiclo==0 || opCiclo==1 || opCiclo==2)
    {
        switch(opCurso)
        {
            case 0:
                cred=5;
                this.txtCostoCredito.setText(""+cred);
                break;
            case 1:
                cred=8;
                this.txtCostoCredito.setText(""+cred);
                break;
            default:
                cred=6;
                this.txtCostoCredito.setText(""+cred);                  
                break;                
        }
    }
    else if (opCiclo==3 || opCiclo==4 || opCiclo==5)
    {
        switch(opCurso)
        {
            case 0:
                cred=6;
                this.txtCostoCredito.setText(""+cred);               
                break;
            case 1:
                cred=2;
                this.txtCostoCredito.setText(""+cred);
                break;
            default:
                cred=8;
                this.txtCostoCredito.setText(""+cred);                  
                break;                
        }
    }
    else
    {
        switch(opCurso)
        {
            case 0:
                cred=2;
                this.txtCostoCredito.setText(""+cred);                   
                break;
            case 1:
                cred=5;
                this.txtCostoCredito.setText(""+cred);
                break;
            default:
                cred=4;
                this.txtCostoCredito.setText(""+cred);                 
                break;                
        }
    }
}                                               

private void btnCalcularActionPerformed(java.awt.event.ActionEvent evt) {                                            

    float resultado;
    float valor1 = Float.parseFloat(this.txtCostoCredito.getText());
    float valor2 = Float.parseFloat(this.txtCreditos.getText());        
    resultado = valor1 * valor2;
    this.txtMontoMatricula.setText(""+resultado);
    //this.txtMontoMatricula

}                                           

public static void main(String args[]) 
{
    java.awt.EventQueue.invokeLater(new Runnable() {

        public void run() {
            FrmCalculaMatricula dialog = new FrmCalculaMatricula(new javax.swing.JFrame(), true);
            dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                @Override
                public void windowClosing(java.awt.event.WindowEvent e) {
                    System.exit(0);
                }
            });
            dialog.setVisible(true);
        }
    });
}

// Variables declaration - do not modify
private javax.swing.JButton btnCalcular;
private javax.swing.JButton btnResumir;
private javax.swing.JButton btnSalir;
private javax.swing.JComboBox cboCiclo;
private javax.swing.JComboBox cboCurso;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JLabel lblApellido;
private javax.swing.JLabel lblCiclo;
private javax.swing.JLabel lblCostoCredito;
private javax.swing.JLabel lblCreditos;
private javax.swing.JLabel lblCurso;
private javax.swing.JLabel lblDatoAlumno;
private javax.swing.JLabel lblMatriculaA;
private javax.swing.JLabel lblMontoMatricula;
private javax.swing.JLabel lblNombre;
private javax.swing.JLabel lblResumenMatricula;
private javax.swing.JTextField txtApellido;
private javax.swing.JTextField txtCostoCredito;
private javax.swing.JTextField txtCreditos;
private javax.swing.JTextField txtMontoMatricula;
private javax.swing.JTextField txtNombre;
private javax.swing.JTextArea txtResumen;
// End of variables declaration

}

1
  • El evento que tienes que controlar es el que salta al seleccionar un elemento en el combo de cursos, así cuando elijas uno de ellos puedes hacer los if y rellenar los textbox el 11 ago. 2017 a las 6:41

1 respuesta 1

1

Se supone que (linea 103)

cboCiclo.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
        cboCicloActionPerformed(evt);
    }
});

realiza la "escucha" de eventos (ActionListener) y delega el evento al método cboCicloActionPerformed()...

Si mira la implementación de éste método, se dará cuenta que no está haciendo nada:

private void cboCicloActionPerformed(java.awt.event.ActionEvent evt) {

}

La lógica que actualiza el txtcredito(Credito) y txtcostocredito(CostoCredito) esta en:

txtCreditosActionPerformed(...

linea 288

ahí debería estar el problema...

Sugerencia

la palabra reservada import sirve precisamente para quitar tanto desorden y "re-llamado" a la misma clase varías veces.

en vez de tener por ejemplo:

new javax.swing.JPanel(); // ocupa "javax.swing." de más

La forma correcta debería ser:

package xxxxx;

import javax.swing.JPanel;

y en su caso, sería mejor aún:

import javax.swing.*;

y quitar todos los javax.swing.... que hace ver horrible el código.

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.