Download interfaz taller de base de datos
Document related concepts
no text concepts found
Transcript
Código de Interfaz Grafica Sistema en Java que utiliza una base de datos y que realiza operaciones como altas, bajas, consultas y actualización de los datos. import java.io.*; import java.awt.*; import java.lang.*; import java.awt.event.*; Librerías necesarias para la ejecución del programa ......................................................................... public class empresas extends Frame { private Label l1, l2, l3, l4, l5; private TextField t1, t2, t3, t4, t7, t8; private Button b1, b2, b3, b4; private TextArea at; Toolkit toolkit; ..................................................................................... Declaración de botones para la interfaz ................................................................... { super ("Proyecto 225"); mostrar (); toolkit = getToolkit (); imagen = toolkit.getImage ("emp.jpg"); } public void paint (Graphics g) { g.drawImage (imagen, 0, 0, this); } l1 = new Label ("Registro de Donaciones y Donantes"); l2 = new Label ("Codigo"); l3 = new Label ("Nombre de Donante"); l4 = new Label ("Tipo de Ayuda"); l5 = new Label ("Cantidad"); b1 = new Button ("Registrar"); b2 = new Button ("Listar"); b3 = new Button ("Eliminar"); b4 = new Button ("Modificar"); t1 = new TextField (""); t2 = new TextField (""); t3 = new TextField (""); t4 = new TextField (""); t7 = new TextField (""); t8 = new TextField (""); at = new TextArea (""); ..................................................................................... Declarando nombre de cada botón que aparecerá en la interfaz ................................................................... l1.reshape (220, 50, 200, 15); l2.reshape (50, 300, 100, 15); l3.reshape (50, 350, 100, 15); l4.reshape (350, 300, 100, 15); l5.reshape (350, 350, 100, 15); b1.reshape (500, 320, 90, 20); b2.reshape (500, 370, 90, 20); b3.reshape (150, 650, 90, 20); b4.reshape (300, 650, 90, 20); t1.reshape (50, 320, 100, 20); t2.reshape (50, 370, 100, 20); t3.reshape (350, 320, 100, 20); t4.reshape (350, 370, 100, 20); t7.reshape (150, 670, 50, 20); t8.reshape (300, 670, 50, 20); at.reshape (50, 400, 540, 230) ..................................................................................... Coordenadas de colocación de cada uno de los elementos de la interfaz ..................................................................................... add (l1); add (l2); add (l3); add (l4); add (l5); add (b1); add (b2); add (b3); add (b4); add (t1); add (t2); add (t3); add (t4); add (t7); add (t8); add (at); resize (700, 700); show (); public void limpiar () { t1.setText (""); t2.setText (""); t3.setText (""); t4.setText (""); t7.setText (""); t8.setText (""); } public boolean action (Event c, Object o) { if (c.arg.equals ("Salir")) { hide (); dispose (); } if (c.arg.equals ("Registrar")) { if (t2.getText ().equals ("") && t3.getText ().equals ("") && t4.getText ().equals ("")) { at.setText ("DEBE COLOCAR LOS DATOR PRIMERO"); return false; } if (t2.getText ().equals ("") | t3.getText ().equals ("") | t4.getText ().equals ("")) { at.setText ("DEBE COLOCAR TODOS LOS DATOR PRIMERO"); return false; } DataOutputStream fos = null; try { ............................................................................................................................. ....... fos = new DataOutputStream (new FileOutputStream ("emp.txt", true)); fos.writeUTF (t1.getText ()); fos.writeUTF (t2.getText ()); fos.writeUTF (t3.getText ()); fos.writeUTF (t4.getText ()); fos.close (); limpiar (); ..................................................................................... Lugar de almacenamiento de los datos ................................................................... } catch (FileNotFoundException fnfe) { at.setText ("Archivo no encontrado"); } catch (IOException ioe) { at.setText ("Error al grabar"); } DataOutputStream fin = null; try { fin = new DataOutputStream (new FileOutputStream ("F:\\emp.txt")); } catch (IOException ioe) { } DataOutputStream fod = null; try { fod = new DataOutputStream (new FileOutputStream ("emp.txt", true)); while (true) { fod.writeUTF (t1.getText ()); fod.close (); } } catch (IOException ioe) { } } if (c.arg.equals ("Listar")) { at.setText (""); DataInputStream fis = null; String Numero, Gestion, Seminario, Docente, Turno, codigo, ApPaterno, ApMaterno, Nombre; try { fis = new DataInputStream (new FileInputStream ("emp.txt")); at.append ("Codigo."); at.append ("\t\tNombre de Donante"); at.append ("\tTipo de Ayuda"); at.append ("\tCantidad"); at.append ("\n\n"); while (true) { Operaciones que se deben de realizar si el usuario si elige la opción eliminar ......................................................................................................... if (c.arg.equals ("Eliminar")) { String nombre, edad, dr, pd, ds, codigo; DataInputStream fisArchivo = null; DataOutputStream fosArchtemp = null; char opcion = 'n'; int sw = 0; try { fosArchtemp = new DataOutputStream (new FileOutputStream ("temporal.txt")); fisArchivo = new DataInputStream (new FileInputStream ("emp.txt")); String cod = t7.getText (); sw = 0; while (true) { codigo = fisArchivo.readUTF (); nombre = fisArchivo.readUTF (); edad = fisArchivo.readUTF (); dr = fisArchivo.readUTF (); pd = fisArchivo.readUTF (); if (cod.equals (codigo)) { sw = 1; } else { fosArchtemp.writeUTF (codigo); fosArchtemp.writeUTF (nombre); fosArchtemp.writeUTF (edad); fosArchtemp.writeUTF (dr); fosArchtemp.writeUTF (pd); limpiar(); } } } catch (IOException variablerror) { } try { fisArchivo.close (); fosArchtemp.close (); if (sw == 1) { File file1 = new File ("emp.txt"); File file2 = new File ("temporal.txt"); if (file1.exists ()) { file1.delete (); } file2.renameTo (file1); } at.setText ("ya se elimino el registro"); } catch (IOException variablerror) { at.setText ("error"); } } .......................................................................................................................................... Operaciones que se deben de realizar si el usuario elige modificar ...................................................................................................... if (c.arg.equals ("Modificar")) { int sw; String nombre, edad, dr, ds, pd, codigo; DataInputStream fisArchivo = null; DataOutputStream fosArchtemp = null; char opcion = 'n'; try { fosArchtemp = new DataOutputStream (new FileOutputStream ("temporal.txt")); fisArchivo = new DataInputStream (new FileInputStream ("emp.txt")); String cod = t8.getText (); sw = 0; while (true) { codigo = fisArchivo.readUTF (); nombre = fisArchivo.readUTF (); edad = fisArchivo.readUTF (); dr = fisArchivo.readUTF (); pd = fisArchivo.readUTF (); if (cod.equals (codigo)) { at.append ("Codigo."); at.append ("\tNombre"); at.append ("\t\tFecha de Nac."); at.append ("\t\t\tDireccion"); at.append ("\t\t\tPadre o apoderado"); at.append ("\t\tDiscapacidad"); at.append ("\n\n"); at.append (codigo + "\t\t" + nombre + "\t\t" + edad + " \t\t" + dr + " \t\t" + pd + " \t\t " + "\n"); codigo = t1.getText (); nombre = t2.getText (); edad = t3.getText (); dr = t4.getText (); } fosArchtemp.writeUTF (codigo); fosArchtemp.writeUTF (nombre); fosArchtemp.writeUTF (edad); fosArchtemp.writeUTF (dr); fosArchtemp.writeUTF (pd); limpiar (); } } catch (IOException variablerror) { } try { fisArchivo.close (); fosArchtemp.close (); File file1 = new File ("emp.txt"); File file2 = new File ("temporal.txt"); if (file1.exists ()) { file1.delete (); } file2.renameTo (file1); at.setText ("ya se modifico el registro"); } catch (IOException variablerror) { at.setText ("error"); } } if (c.arg.equals ("Ninos")) { ninos x = new ninos (); hide (); } if (c.arg.equals ("Voluntarios")) { voluntarios y = new voluntarios (); hide (); } if (c.arg.equals ("Donaciones")) { empresas y = new empresas (); hide (); } if (c.arg.equals ("Institucion")) { instituto y = new instituto (); hide (); } if (c.arg.equals ("Volver")) { proyecto y = new proyecto (); hide (); } if (c.arg.equals ("Salir")) { hide (); dispose (); } if (c.arg.equals ("Capacitacion")) { capacitacion y = new capacitacion (); hide (); } return true; } public static void main (String args[]) { empresas x = new empresas (); x.setCursor (new Cursor (Cursor.HAND_CURSOR)); x.addWindowListener (new WindowAdapter () { public void windowClosing (WindowEvent e) { System.exit (0); } } ); } }