2practica 1POO
2practica 1POO
2practica 1POO
PRACTICA 1
Código de la clase:
package pracAlumno_9;
/**
*
* @author Gonzalo_Mendoza
*/
public class Alumno {
private String numBoleta;
private String Nombre;
private String Carrera;
private String Grupo;
public Alumno() {
}
/**
* Creates new form Registro
*/
public Registro() {
MANUEL GONZALO MENDOZA GUTIERREZ
PRACTICA 1
initComponents();
}
public void limpiar(){
this.jTextField1.setText(null);
this.jTextField2.setText(null);
this.jTextField3.setText(null);
this.jTextField4.setText(null);
this.jLabel5.setIcon(null);
this.jTextField1.requestFocus();
}
public void grabar(){
if(i>4){
System.out.println("Arreglo lleno");
}
else{
String bo, nom, car, grup;
bo=this.jTextField1.getText();
nom=this.jTextField2.getText();
car=this.jTextField3.getText();
grup=this.jTextField4.getText();
alumno [i]= new Alumno (bo, nom, car, grup);
System.out.println("Los datos se han grabado correctamente");
foto=Toolkit.getDefaultToolkit().getImage("./src/fotosalumno/"+this.jTextField1.getText()
+".jpg");
this.jLabel5.setIcon(new ImageIcon(foto.getScaledInstance(140, 140, 0)));
i++;
if(i>4)this.btngrabar.setVisible(false);
}
This.limpiar();
}
public void Buscar(){
String bo=this.jTextField1.getText();
try{
for (i = 0; i<=4 ;i++){
if(bo.equals(alumno[i].getNumBoleta())){
this.jTextField2.setText(alumno[i].getNombre());
this.jTextField3.setText(alumno[i].getCarrera());
this.jTextField4.setText(alumno[i].getGrupo());
foto=Toolkit.getDefaultToolkit().getImage("./src/fotosalumno/"+this.jTextField1.getText()+".jpg");
this.jLabel5.setIcon(new ImageIcon(foto.getScaledInstance(140, 140, 0)));
}
}
}catch(NullPointerException e){
System.out.println(e);
}
}
public void eliminar(){
String bo, nom = null, car = null, grup = null;
MANUEL GONZALO MENDOZA GUTIERREZ
PRACTICA 1
bo=this.jTextField1.getText();
try{
for(int i=0; i<=4 ;i++){
if(bo.equals(alumno[i].getNumBoleta())){
bo = null;
alumno[i].setNumBoleta(bo);
alumno[i].setNombre(nom);
alumno[i].setCarrera(car);
alumno[i].setGrupo(grup);
JOptionPane.showMessageDialog(null, "Alumno eliminado correctamente");
This.limpiar();
}
}
} catch(NullPointerException e){
System.out.println(e);
}
this.jTextField3.setText(alumno[i].getCarrera());
this.jTextField4.setText(alumno[i].getGrupo());
foto=Toolkit.getDefaultToolkit().getImage("./src/fotosalumno/"+this.jTextField1.getText()
+".jpg");
this.jLabel5.setIcon(new ImageIcon(foto.getScaledInstance(140, 140, 0)));
}
/**
* 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")
private void jButton5MouseClicked(java.awt.event.MouseEvent evt) {
this.limpiar();
// TODO add your handling code here:
}
}
public static void main(String args[]) {
/* Set the Nimbus look and feel */
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Registro().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnanterior;
private javax.swing.JButton btngrabar;
private javax.swing.JButton btnprimero;
private javax.swing.JButton btnsiguiente;
private javax.swing.JButton btnultimo;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;
private javax.swing.JButton jButton9;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
// End of variables declaration
}
MANUEL GONZALO MENDOZA GUTIERREZ
PRACTICA 1
MANUEL GONZALO MENDOZA GUTIERREZ
PRACTICA 1