Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

2practica 1POO

Descargar como docx, pdf o txt
Descargar como docx, pdf o txt
Está en la página 1de 8

MANUEL GONZALO MENDOZA GUTIERREZ

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() {
}

public Alumno(String numBoleta, String Nombre, String Carrera, String Grupo) {


this.numBoleta = numBoleta;
this.Nombre = Nombre;
this.Carrera = Carrera;
this.Grupo = Grupo;
}

public String getGrupo() {


return Grupo;
}

public void setGrupo(String Grupo) {


this.Grupo = Grupo;
}

public String getNumBoleta() {


return numBoleta;
}

public void setNumBoleta(String numBoleta) {


this.numBoleta = numBoleta;
}

public String getNombre() {


return Nombre;
}

public void setNombre(String Nombre) {


this.Nombre = Nombre;
}

public String getCarrera() {


return Carrera;
}

public void setCarrera(String Carrera) {


this.Carrera = Carrera;
}
MANUEL GONZALO MENDOZA GUTIERREZ
PRACTICA 1

public String mostrarDatos(){


return "numero de Boleta: " +this.getNumBoleta()+ "\n"
+ "Nombre del alumno: " +this.getNombre()+ "\n"
+ "Carrera: " +this.getCarrera()+ "\n"
+ "Grupo: " +this.getGrupo();
}
}

Diseño del Jframe

Codigo del Jframe


package pracAlumno_9;
import java.awt.Image;
import java.awt.Toolkit;
import java.util.Optional;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
/**
*
* @author Gonzalo_Mendoza
*/
public class Registro extends javax.swing.JFrame {
Alumno [] alumno=new Alumno[5];
int i=0;
Image foto;

/**
* 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);
}

public void siguiente(){


i++;
if(i>4){
System.out.println("Este es el primer alumno");
i=4;
this.llenar();
}else{
this.llenar();
}
}
public void anterior(){
i--;
if(i<0){
System.out.println("Este es el ultimo alumno");
i=0;
this.llenar();
}else{
this.llenar();
}
}
public void ultimo()
{
i=4;
this.llenar();
}
public void primero(){
i=0;
this.llenar();
}
public void llenar(){
this.jTextField1.setText(alumno[i].getNumBoleta());
this.jTextField2.setText(alumno[i].getNombre());
MANUEL GONZALO MENDOZA GUTIERREZ
PRACTICA 1

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:
}

private void btngrabarMouseClicked(java.awt.event.MouseEvent evt) {


this.grabar();
// TODO add your handling code here:
}

private void jButton9MouseClicked(java.awt.event.MouseEvent evt) {


System.exit(0);
// TODO add your handling code here:
}

private void btnprimeroMouseClicked(java.awt.event.MouseEvent evt) {


this.primero();
// TODO add your handling code here:
}

private void btnanteriorMouseClicked(java.awt.event.MouseEvent evt) {


this.anterior();
// TODO add your handling code here:
}

private void btnsiguienteMouseClicked(java.awt.event.MouseEvent evt) {


this.siguiente();
// TODO add your handling code here:
}

private void btnultimoMouseClicked(java.awt.event.MouseEvent evt) {


this.ultimo();
// TODO add your handling code here:
}

private void jButton7MouseClicked(java.awt.event.MouseEvent evt) {


this.Buscar();
// TODO add your handling code here:
MANUEL GONZALO MENDOZA GUTIERREZ
PRACTICA 1

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


// TODO add your handling code here:
}

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


// TODO add your handling code here:
}

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


this.eliminar();
}

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

}
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

También podría gustarte