Sistema integral de gestión de consultas de información estudiantil Programación JAVA
prueba de paquete;
importar java.sql.*;
importar java.awt.*
importar javax.swing. *;
importar java.awt.event.*;
importar javax.swing.border.*
importar javax.swing.JOptionPane
p>
importar javax.swing.border.*;
importar javax.swing.JOptionPane;
p>
clase Agregar extiende el Panel implementa ActionListener{
Conexión con;
Declaración sql;
Botón b1, b2
TextField tf1, tf2, tf3, tf4, tf5, tf6; /p>
Caja baseBox, bv1, bv2;
Add(){
try{
p>
Class.forName(" sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
intente {
con= DriverManager.getConnection("jdbc:odbc:data","","");
sql=con.createStatement()
}
captura (SQLException ee){}
setLayout(nuevo BorderLayout());
Panel p1=nuevo Panel()
Panel p2=nuevo Panel();
tf1=nuevo Campo de Texto(16);
tf2=nuevo Campo de Texto(16);
tf3= nuevo Campo de Texto(16);
tf4=nuevo Campo de Texto(16);
tf5=nuevo Campo de Texto(16);
tf6=nuevo Campo de Texto(16)
b1=; nuevo Botón("Entrar");
b1.setBackground(Color.green);
b2=nuevo Botón("Restablecer"
b2. setBackground(Color.verde);
b1.addActionListener(this);
b2.addActionListener(this);
p1.add(b1); /p>
p1.add(b2);
bv1=Box.createVerticalBox();
bv1.add( new Label("Número de estudiante"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("Nombre")); Box.createVerticalStrut(8));
bv1.add(new Label("Género"));
bv1.add(Box.createVerticalStrut(8)); >
bv1.add(new Label("Profesional"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label( "Calificación"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("Nacimiento")); p> bv1.add(Box.createVerticalStrut(8));
bv2=Box.createVerticalBox()
bv2.add(tf1); bv2.add(Box.createVerticalStrut(8));
bv2.add(tf2
bv2.add(Box.createVerticalStrut(8)); p> bv2.add(tf3);
bv2.add(Box.createVerticalStrut(8));
bv2.add(tf4); .add(Box.createVerticalStrut(8));
bv2.add(tf5
bv2.add(Box.createVerticalStrut(8)); > bv2.add(tf6);
bv2.add(Box.createVerticalStrut(8));
baseBox=Box.createHorizontalBox(); .add(bv1);
baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(bv2); baseBox);
add(p1, "Sur");
add(p2, "Centro"); /p>
setBackground(Color.pink);
}
public void actionPerformed(ActionEvent e){
if(e.getSource() ==b1){
intentar{ insertar();}
catch(SQLException ee){}
JOptionPane.showMessageDialog(this, "¡Los datos se han almacenado en la base de datos!", "Cuadro de diálogo emergente", JOptionPane.INFORMATION_MESSAGE);
}
else if(e.getSource( )== b2){
tf1.setText(" ");
tf2.setText(" ");
p>
tf4.setText(" ");
tf5.setText(" ");
}
}
public void insert() lanza SQLException{
String s1="'" tf1.getText() .trim() "'";
Cadena s2="'" tf2.getText().trim() "'";
Cadena s3="'" tf3.getText; ().trim() "' ";
Cadena s4="'" tf4.getText().trim() "'"; .getText().trim() "'";
Cadena s6="'" tf6.getText().trim() "'"; EN VALORES jesse (" s1 ", " s2 ", " s3 ", " s4 ", " s5 ", " s6 ")";
con=DriverManager.getConnection("jdbc:odbc:data" , "", "");
sql.executeQuery(temp);
con.close()
}
; }
clase Consulta extiende Panel implementa ActionListener{
Conexión con
Declaración sql
TextField t1, t2, t3, t4; , t5, t6;
Botón b;
Caja baseBox, bv1, bv2; ){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); ClassNotFoundException e){}
try{
con=DriverManager.getConnection("jdbc:odbc:data","","");
sql=con.createStatement();
}
catch(SQLException ee){}
setLayout(new BorderLayout()); p> b=nuevo Botón("consulta");
b.setBackground(Color.orange
b.addActionListener(this); =nuevo Campo de Texto(8);
t2=nuevo Campo de Texto(16);
t3=nuevo Campo de Texto(16);
t4=nuevo Campo de Texto(16);
t5=nuevo Campo de Texto(16);
t6=nuevo Campo de Texto(16);
t2.setEditable(false);
t3.setEditable(falso);
t4.setEditable(falso);
t5.setEditable(falso);
t6.setEditable(falso);
Panel p1=new Panel(), p2=new Panel();
p1.add(new Label("Ingrese el número de estudiante a consultar");
p1.add(t1);
p1.add(b
bv1=Box.createVerticalBox(); bv1 .add(new Label("Nombre"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("Género") ) ;
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("Profesional")); agregar (Box.createVerticalStrut(8));
bv1.add(new Label("Calificación");
bv1.add(Box.createVerticalStrut(8)); /p>
p>
bv1.add(new Label("nacimiento"));
bv1.add(Box.createVerticalStrut(8)); bv2=Box.createVerticalBox( );
bv2.add(t2
bv2.add(Box.createVerticalStrut(8));
bv2. agregar(t3);
bv2.add(Box.createVerticalStrut(8));
bv2.add(t4);
bv2.add(Box.createVerticalStrut(8));
bv2.add(t5
bv2.add(Box.createVerticalStrut(8)); p> bv2.add(t6);
bv2.add(Box.createVerticalStrut(8));
baseBox=Box.createHorizontalBox(); baseBox.add(bv1);
baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(bv2); (baseBox);
add(p1, "Norte");
add(p2, "Centro");
setBackground(Color.red);
}
public void actionPerformed(ActionEvent e){
flag=0; p>
p>
try{query();}
catch(SQLException ee){}
}
consulta vacía pública( ) arroja SQLException{
Número de cadena, nombre, sexo, materia, grado, nacimiento
con=DriverManager.getConnection("jdbc:odbc:data","",""
ResultSet rs=sql.executeQuery("SELECCIONAR * DE jesse "); .getString("número");
nombre=rs.getString("nombre");
sexo=rs.getString("género"); p> sujeto=rs .getString("mayor");
grado=rs.getString("grado");
nacido=rs.getString("nacimiento"); /p>
if(num.equals(t1.getText().trim())){
t2.setText(nombre
t3.setText(sexo);
t4.setText(sujeto);
t5.setText(grado
t6.setText(nacido); > bandera=1;
romper
}
}
con.close();
/p>
if(flag==0){t1.setText("No existe tal estudiante");}
}
}
clase Actualización extiende Panel implementa ActionListener{
Conexión con;
Instrucción sql;
Botón b1, b2, b3; baseBox, bv1, bv2;
TextField t1, t2, t3, t4, t5, t6
Actualizar(){
probar{
;Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
intentar{
con=DriverManager.getConnection("jdbc:odbc:data","","");
sql=con.createStatement()
}
p>
catch(SQLException ee){}
setLayout(new BorderLayout());
b1=new Button("Comenzar a modificar"
b1.setBackground(Color.green);
b2=new Button("Ingresar cambios");
b3=new Button("Restablecer");
b3.setBackground(Color.amarillo);
b1.addActionListener(this); /p>
b2.addActionListener(este);
b3.addActionListener(este);
t1=new TextField(8); =nuevo Campo de Texto(16)
t3=nuevo Campo de Texto(16);
t4=nuevo Campo de Texto(16);
t5=nuevo Campo de Texto(16);
t6=nuevo TextField(16);
Panel p1=nuevo Panel(), p2=nuevo Panel(), p3=nuevo Panel();
p1.add (new Label("Ingrese el número del estudiante cuya información desea modificar"));
p1.add(t1); b1);
bv1=Box.createVerticalBox();
bv1.add(new Label("(nuevo) apellido
nombre"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("(Nuevo)Género"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("(Nuevo)Profesional")); Box.createVerticalStrut(8));
bv1.add(new Label("(nuevo) grado"));
bv1.add(new Label("(Nuevo) Nacido"));
bv1.add(Box.createVerticalStrut(8)); =Box.createVerticalBox();
bv2.add(t2
bv2.add(Box.createVerticalStrut(8));
bv2.add (t3);
bv2.add(Box.createVerticalStrut(8));
bv2.add(t4);
bv2.add(Box. createVerticalStrut(8));
bv2.add(t5);
bv2.add(Box.createVerticalStrut(8));
bv2.add( t6);
bv2.add(Box.createVerticalStrut(8));
baseBox=Box.createHorizontalBox()
baseBox.add(bv1)
baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(bv2); p>
p>
p3.add(b2);
p3.add(b3);
add(p1, "Norte"); >
agregar (p2, "Centro");
agregar(p3, "Sur"
setSize(300, 250); setBackground(Color.cyan );
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
try{
String num, nombre, sexo, materia, grado, nacimiento
con=DriverManager.ge;
tConnection("jdbc:odbc:data","","");
ResultSet rs=sql.executeQuery("SELECT * FROM jesse "); next()){
num=rs.getString("número de estudiante");
nombre=rs.getString("nombre"); =rs.getString("Género");
sujeto=rs.getString("Mayor");
grado=rs.getString("Calificación");
nacido=rs.getString("nacimiento");
if(num.equals(t1.getText().trim())){
t2.setText( nombre);
t3.setText(sexo);
t4.setText(sujeto);
t5.setText(grado); p> t6.setText(nacido);
romper
}
}
con.close(); >
}
catch(SQLException ee){}
}
if(e.getSource()==b2){
try{update();}
catch(SQLException ee){}
}
if(e.getSource()==b3) {
t2.setText(" ");
t3.setText(" ");
t5.setText(" ");
t6.setText(" "
}
}
público void update() lanza SQLException{
String s1="'" t1.getText().trim() "'"
String s2="'" t2.getText( ).trim() "'";
Cadena s3="'" t3.getText().trim() "'";
Cadena s4="'" t4. getText().trim() "'";
Cadena s5="'"
t5.getText().trim() "'";
Cadena s6="'" t6.getText().trim() "'"; ACTUALIZACIÓN jesse SET nombre=" s2 ", género=" s3 ", mayor=" s4 ", grado=" s5 ", nacimiento=" s6 " DONDE número de estudiante=" s1;
con=DriverManager. getConnection("jdbc:odbc:data","","");
sql.executeQuery(temp
con.close(); > }
}
clase Eliminar extiende Panel implementa ActionListener{
Conexión con
Declaración sql; > TextField t1, t2, t3, t4, t5, t6;
Botón b
Caja baseBox, bv1, bv2; /p>
intentar{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e) {}
intente{
con=DriverManager.getConnection("jdbc:odbc:data","","");
sql=con. createStatement();
}
catch(SQLException ee){}
setLayout(new BorderLayout()); nuevo Botón("Eliminar");
b.setBackground(Color.cyan);
b.addActionListener(this); 8);
t1.addActionListener(this);
t2=nuevo TextField(16);
t3=nuevo TextField(16); >
t4=nuevo Campo de Texto(16);
t5=nuevo Campo de Texto(16);
t6=nuevo Campo de Texto(16); .setEditable(falso);
t3.setEditable(falso);
t4.setEditable(falso);
t5.setEditable(falso); p>
p>
t6.setEditable(fals
e);
Panel p1=new Panel(), p2=new Panel();
p1.add(new Label("Ingrese el número de estudiante que desea eliminar"))
p1.add(t1);
p1.add(b
bv1=Box.createVerticalBox(); > bv1.add(new Label("Nombre"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("Género"); ) );
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("Profesional")); add(Box.createVerticalStrut(8));
bv1.add(new Label("Calificación"));
bv1.add(new Label("nacimiento"));
bv1.add(Box.createVerticalStrut(8));
bv2=Box. crearVerticalBox ();
bv2.add(t2);
bv2.add(Box.createVerticalStrut(8));
bv2.add(t3)
bv2.add(Box.createVerticalStrut(8));
bv2.add(t4);
bv2.add(Box.createVerticalStrut(8); ) );
bv2.add(t5);
bv2.add(Box.createVerticalStrut(8));
bv2.add(t6);
bv2.add(Box.createVerticalStrut(8));
baseBox=Box.createHorizontalBox();
baseBox.add(bv1); p >
baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(bv2);
p2.add(baseBox); p > add(p1, "Norte");
add(p2, "Centro");
setSize(300, 250);
setBackground( Color .verde);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==t1){
prueba{de
lete();}
catch(SQLException ee){}
}
else if(e.getSource()==b){
int n=JOptionPane.showConfirmDialog(this, "¿Está seguro de que desea eliminar la identificación del estudiante y toda la información?", "OK", JOptionPane.YES_NO_OPTION
if(n=); =JOptionPane.YES_OPTION){
intentar{
String s1="'" t1.getText().trim() "'"; ="BORRAR DE jesse DONDE número de estudiante=" s1;
con=DriverManager.getConnection("jdbc:odbc:data","",""); (temp)
con.close();
}
catch(SQLException ee){}
}
else if(n==JOptionPane.NO_OPTION){}
}
}
public void eliminar() lanza SQLException{
String num, nombre, sexo, materia, grado, nacimiento
con=DriverManager.getConnection("jdbc:odbc:data", "", ""); p> ResultSet rs=sql.executeQuery("SELECT * FROM jesse ");
while(rs.next()){
num=rs.getString("ID del estudiante" );
nombre=rs.getString("Nombre");
sexo=rs.getString("Género"); ("Profesional ");
grado=rs.getString("grado"
born=rs.getString("nacimiento"); (num. igual a (t1.getText().trim())){
t2.setText(nombre
t3.setText(sexo); p> t4 .setText(sujeto);
t5.setText(grado
t6.setText(nacido);
> romper;
}
}
con.close(); p>
p>
clase pública tyj extiende Frame implementa ActionListener{
MenuBar bar=null
Menú menú1, menú2, menú3, menú4, menú5
p>Elemento de menú elemento1, elemento2, elemento3, elemento4, elemento5
Agregar zengjia
Consulta chaxun
Actualizar gengxin;
Eliminar shanchu ;
tyj(){
super("Bienvenido al sistema de gestión de información de estudiantes");
zengjia=new Add();
chaxun=nueva consulta();
gengxin=nueva actualización();
shanchu=nueva eliminación(); bar=new MenuBar()
menu1=new Menu("Ingreso de información"
menu2=new Menu("Consulta de información"); menu3=new Menu("Actualización de información");
menu4=new Menu("Eliminación de información");
menu5=new Menu("Salir del sistema"); >
item1= new MenuItem("Entrar");
item2=new MenuItem("Consulta");
item3=new MenuItem("Actualizar"); p>
item4 =new MenuItem("Eliminar");
item5=new MenuItem("Salir");
menu1.add(item1);
menú2.add (elemento2);
menú3.add(elemento3);
menú4.add(elemento4);
menú5.add(elemento5);
bar.add(menú1);
bar.add(menú2
bar.add(menú3); > bar.add(menu4 );
bar.add(menu5);
setMenuBar(bar);
item1.addActionListener(this); p>
elemento2 .addActionListener(este);
elemento3.addActionListener(este
elemento4.addActionListener(este);
);
item5.addActionListener(this);
Label label=new Label("Bienvenido al Sistema de gestión de información estudiantil", Label.CENTER); > Cadena s=" ";
Fuente f=nueva Fuente(s,Font.BOLD,22
etiqueta.setFont(f); etiqueta .setBackground(Color.GREEN);
label.setForeground(Color.BLUE
add(label, "Centro"); verdadero );
setSize(320, 300);
}
acción vacía públicaPerformed(ActionEvent e){
if(e). . getSource()==item1){
removeAll();
add(zengjia, "Centro"); >
}
if(e.getSource()==item2){
removeAll()
add(chaxun, "Centro")
validar();
}
if(e.getSource()==item3){
removeAll();
add(gengxin, "Centro");
validar()
}
if(e.getSource()= = elemento4){
removeAll();
add(shanchu, "Centro"
validar();
if(e.getSource()==item5){
removeAll()
setBackground(Color.GREEN); > Etiqueta etiqueta=nueva Etiqueta("Bienvenido al Sistema de Gestión de Información Estudiantil", Etiqueta.CENTRO
String s="
Fuente f=nueva Fuente(s), Fuente. BOLD, 22);
label.setFont(f);
label.setForeground(Color.BLUE); ") ;
validar();
}
}
público estático vacío principal (S
tring[] args)
{
tyj jesse=new tyj();
jesse.setVisible(true); .addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
}