package avioncito; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.*; public final class Ventana extends JFrame implements ActionListener{ class IngresoAerolineas { String nombrepropietario; String pais; int fundacion; String Aeropuertoprinci; String Aeropuertosecun; String Sede; int Flota; int destinos; IngresoAerolineas enlace; public IngresoAerolineas(String a, String aa, int aaa, String aaaa, String aaaaa, String aaaaaa, int aaaaaaa, int aaaaaaaa ) { nombrepropietario= a; pais=aa; fundacion=aaa; Aeropuertoprinci=aaaa; Aeropuertosecun=aaaaa; Sede=aaaaaa; Flota=aaaaaaa; destinos=aaaaaaaa; enlace = null; } } private class IngresoAerolinea { public IngresoAerolineas inicio; public IngresoAerolinea() { inicio = null; } public IngresoAerolinea insertarcabeza(String a, String aa, int aaa, String aaaa, String aaaaa, String aaaaaa, int aaaaaaa, int aaaaaaaa) { IngresoAerolineas nuevo = new IngresoAerolineas (a,aa,aaa,aaaa,aaaaa,aaaaaa,aaaaaaa,aaaaaaaa); nuevo.enlace = inicio; inicio = nuevo; return this; } public void visualiza() { IngresoAerolineas actual; actual = inicio; while (actual != null) { JOptionPane.showMessageDialog(null,""+actual.nombrepropietario +"\n"+actual.pais +"\n"+actual.fundacion +"\n"+actual.Aeropuertoprinci +"\n"+actual.Aeropuertosecun +"\n"+actual.Sede +"\n"+actual.Flota +"\n"+actual.destinos ); actual = actual.enlace; } } public void add(IngresoAerolineas newNodo){ //puntero temporal para recorreme en la lista IngresoAerolineas tmp = inicio; //si la lista esta vacia if(tmp==null){ //lo agregamos al root inicio = newNodo; }else{ //de lo contrario nos recorremos hasta el ultimo while(tmp.enlace!=null) tmp = tmp.enlace; //en el ultimo hacemos el enlace tmp.enlace = newNodo; } } public IngresoAerolinea insertar(String a, String aa, int aaa, String aaaa, String aaaaa, String aaaaaa, int aaaaaaa, int aaaaaaaa, IngresoAerolineas j) { IngresoAerolineas nuevo = new IngresoAerolineas (a,aa,aaa,aaaa,aaaaa,aaaaaa,aaaaaaa,aaaaaaaa); nuevo.enlace = j.enlace; j.enlace = nuevo; return this; } } class IngresoAviones { String avion; String Aeronave; String motor; int pasajeros; String destinos; IngresoAviones enlace2; public IngresoAviones(String d, String dd, String ddd, int dddd, String ddddd) { avion=d; Aeronave=dd; motor=ddd; pasajeros=dddd; destinos=ddddd; enlace2 = null; } } private class IngresoAvion { public IngresoAviones inicio2; public IngresoAvion() { inicio2 = null; } public IngresoAvion insertarcabeza(String d, String dd, String ddd, int dddd, String ddddd) { IngresoAviones nuevo = new IngresoAviones(d,dd,ddd,dddd,ddddd); nuevo.enlace2 = inicio2; inicio2 = nuevo; return this; } public void visualiza() { IngresoAviones actual; actual = inicio2; while (actual != null) { JOptionPane.showMessageDialog(null,""+actual.avion +"\n"+actual.Aeronave+"\n"+actual.motor+"\n"+actual.pasajeros +"\n"+actual.destinos); actual = actual.enlace2; } } public void add(IngresoAviones newNodo){ //puntero temporal para recorreme en la lista IngresoAviones tmp = inicio2; //si la lista esta vacia if(tmp==null){ //lo agregamos al root inicio2 = newNodo; }else{ //de lo contrario nos recorremos hasta el ultimo while(tmp.enlace2!=null) tmp = tmp.enlace2; //en el ultimo hacemos el enlace tmp.enlace2 = newNodo; } } public IngresoAvion insertar(String d, String dd, String ddd, int dddd, String ddddd, IngresoAviones h) { IngresoAviones nuevo = new IngresoAviones (d,dd,ddd,dddd,ddddd); nuevo.enlace2 = h.enlace2; h.enlace2 = nuevo; return this; } } class Ingresovuelos { String vuelo; String ruta; String Fsalida; String Fllegada; String Hsalida; String Hllegada; int Pasajeros; Ingresovuelos enlace3; public Ingresovuelos(String m,String mm,String mmm,String mmmm,String mmmmm, String mmmmmm, int mmmmmmm) { vuelo=m; ruta=mm; Fsalida=mmm; Fllegada=mmmm; Hsalida=mmmmm; Hllegada=mmmmmm; Pasajeros=mmmmmmm; enlace3 = null; } } private class Ingresovuelo { public Ingresovuelos inicio3; public Ingresovuelo() { inicio3 = null; } public Ingresovuelo insertarcabeza(String m, String mm,String mmm,String mmmm,String mmmmm, String mmmmmm, int mmmmmmm) { Ingresovuelos nuevo = new Ingresovuelos(m,mm,mmm,mmmm,mmmmm,mmmmmm,mmmmmmm); nuevo.enlace3 = inicio3; inicio3 = nuevo; return this; } public void visualiza() { Ingresovuelos actual; actual = inicio3; while (actual != null) { JOptionPane.showMessageDialog(null,"Avión: "+actual.vuelo +"\n"+"Ruta: "+actual.ruta +"\n"+"Fecha Salida: "+actual.Fsalida +"\n"+"Fecha de Llegada: "+actual.Fllegada +"\n"+"Hora de salida "+actual.Hsalida +"\n"+"Hora Llegada: "+actual.Hllegada +"\n"+"Cantidad de Pasajeros: "+actual.Pasajeros ); actual = actual.enlace3; } } public void add(Ingresovuelos newNodo){ //puntero temporal para recorreme en la lista Ingresovuelos tmp = inicio3; //si la lista esta vacia if(tmp==null){ //lo agregamos al root inicio3 = newNodo; }else{ //de lo contrario nos recorremos hasta el ultimo while(tmp.enlace3!=null) tmp = tmp.enlace3; //en el ultimo hacemos el enlace tmp.enlace3 = newNodo; } } public Ingresovuelo insertar(String m, String mm, String mmm,String mmmm,String mmmmm, String mmmmmm, int mmmmmmm, Ingresovuelos o) { Ingresovuelos nuevo = new Ingresovuelos (m,mm,mmm,mmmm,mmmmm,mmmmmm,mmmmmmm); nuevo.enlace3 = o.enlace3; o.enlace3 = nuevo; return this; } public Ingresovuelos Buscar(String mm) { Ingresovuelos j; try { for (j = inicio3; j != null; j = j.enlace3) { if (mm == j.ruta) { return j; } else { JOptionPane.showMessageDialog(null, j.ruta); } } } catch (Exception e) { } return null; } public String biscari(){ String bus=""; for(Ingresovuelos j=inicio3; j!=null; j=j.enlace3) bus+=j.ruta+"\n"; return bus; } } private JPanel Panel1, Panel2; private JButton triangulo, ingresoaero, ingresoavion, veraviones, veraerolineas; private JLabel etiqueta1; private JTextField nombre,apellidos,cc,telefono,residencia,direccion, Nro_pasaporte; private JDialog vAcerca, vformuaerolineas, vformulavion ; private JTextArea area; private IngresoAerolinea l; IngresoAvion k; Ingresovuelo n; JMenuBar barra = new JMenuBar(); JMenu programa = new JMenu("Programa"); JMenu ayuda = new JMenu("Ayuda"); JMenu guardar = new JMenu("Guardar"); public Ventana () { super("Aerolineas"); setJMenuBar(barra); barra.add(programa); barra.add(ayuda); programa.add("Nuevo"); l = new IngresoAerolinea(); k = new IngresoAvion(); n = new Ingresovuelo(); programa.add("Salir"); programa.addActionListener(this); ayuda.add("Ayuda General"); ayuda.addSeparator(); ayuda.add("Acerca de..."); ayuda.addActionListener(this); this.getContentPane().setLayout(null); this.setSize(660, 730); this.setResizable(false); this.setLocationRelativeTo(null); // creaPanel1(); // creaPanel2(); creaPanel3(); addWindowListener(new WindowAdapter(){ @Override public void windowOpened(WindowEvent e){ vAcercade(); } @Override public void windowClosing(WindowEvent e){ dispose(); } }); } private void vAcercade (){ vAcerca = new JDialog(this, "Acerca de...", true); vAcerca.setLayout(null); vAcerca.setSize(300, 200); vAcerca.setResizable(false); vAcerca.setLocation(644,344); vAcerca.setVisible(false); } private void creaPanel1() { Panel1 = new JPanel(); Panel1.setLayout(null); Panel1.setBorder(BorderFactory.createTitledBorder("AeroLineas")); Panel1.setBounds(10,10,180,200); ingresoaero = new JButton ("Aerolinea"); ingresoaero.setBounds(20,20,150,30); ingresoaero.addActionListener(this); Panel1.add(ingresoaero); ingresoavion = new JButton ("Avion"); ingresoavion.setLayout(null); ingresoavion.setBounds(20, 55,150,30); ingresoavion.addActionListener(this); Panel1.add(ingresoavion); veraerolineas = new JButton ("Ver Aerolineas"); veraerolineas.setLayout(null); veraerolineas.setBounds(20,90,150,30); veraerolineas.addActionListener(this); Panel1.add(veraerolineas); veraviones = new JButton ("VEr Aviones"); veraviones.setLayout(null); veraviones.setBounds(20, 125,150,30); veraviones.addActionListener(this); Panel1.add(veraviones); getContentPane().add(Panel1); } private void creaPanel2() { Panel2 = new JPanel(); Panel2.setLayout(null); Panel2.setBorder(BorderFactory.createTitledBorder("Reserva vuelo")); Panel2.setBounds(200,30,410,140); etiqueta1 = new JLabel("Nombres"); etiqueta1.setBounds(20,20,80,20); Panel2.add(etiqueta1); nombre = new JTextField(); nombre.setBounds(100, 20, 80, 20); nombre.setEditable(true); Panel2.add(nombre); etiqueta1 = new JLabel("Apellidos"); etiqueta1.setBounds(20,50,80,20); Panel2.add(etiqueta1); apellidos = new JTextField(); apellidos.setBounds(100, 50, 80, 20); apellidos.setEditable(true); Panel2.add(apellidos); etiqueta1 = new JLabel("CC"); etiqueta1.setBounds(20,80,80,20); Panel2.add(etiqueta1); cc = new JTextField(); cc.setBounds(100, 80, 80, 20); cc.setEditable(true); Panel2.add(cc); etiqueta1 = new JLabel("Direccion"); etiqueta1.setBounds(20,110,80,20); Panel2.add(etiqueta1); direccion = new JTextField(); direccion.setBounds(100, 110, 80, 20); direccion.setEditable(true); Panel2.add(direccion); etiqueta1 = new JLabel("Telefono"); etiqueta1.setBounds(200,20,100,20); Panel2.add(etiqueta1); telefono = new JTextField(); telefono.setBounds(300, 20, 80, 20); telefono.setEditable(true); Panel2.add(telefono); etiqueta1 = new JLabel("residencia"); etiqueta1.setBounds(200,50,100,20); Panel2.add(etiqueta1); residencia = new JTextField(); residencia.setBounds(300, 50, 80, 20); residencia.setEditable(true); Panel2.add(residencia); etiqueta1 = new JLabel("Nro de pasaporte"); etiqueta1.setBounds(200,80,100,20); Panel2.add(etiqueta1); residencia = new JTextField(); residencia.setBounds(300, 80, 80, 20); residencia.setEditable(true); Panel2.add(residencia); getContentPane().add(Panel2); } private void creaPanel3() { Panel1 = new JPanel(); Panel1.setLayout(null); Panel1.setBorder(BorderFactory.createTitledBorder("Ingreso de vuelos")); Panel1.setBounds(10,230,180,200); ingresoaero = new JButton ("Ingresar Vuelo"); ingresoaero.setBounds(20,20,150,30); ingresoaero.addActionListener(this); Panel1.add(ingresoaero); ingresoaero = new JButton ("Ver Vuelo"); ingresoaero.setBounds(20,50,150,30); ingresoaero.addActionListener(this); Panel1.add(ingresoaero); ingresoaero = new JButton ("Buscar Vuelo"); ingresoaero.setBounds(20,80,150,30); ingresoaero.addActionListener(this); Panel1.add(ingresoaero); area = new JTextArea(); area.setBounds(20, 100, 100,100); Panel1.add(area); getContentPane().add(Panel1); } public void actionPerformed(ActionEvent e) { if (e.getActionCommand () == "Ingresar Aerolinea") { String b = JOptionPane.showInputDialog("INGRESE NUEVA AEROLINEA"); String bb = JOptionPane.showInputDialog("INGRESE PAIS DONDE FUNCIONA"); String bbb = JOptionPane.showInputDialog("INGRESE FECHA DE FUNDACIÓN"); int bbbq = Integer.parseInt(bbb); String bbbb = JOptionPane.showInputDialog("INGRESE AEROPUERTO PRINCIPAL"); String bbbbb = JOptionPane.showInputDialog("INGRESE AEROPUERTO SECUNDARIO"); String bbbbbb = JOptionPane.showInputDialog("INGRESE SEDE CENTRAL"); String bbbbbbb = JOptionPane.showInputDialog("INGRESE FLOTA DE AVIONES"); int bbbbbbbq = Integer.parseInt(bbbbbbb); String bbbbbbbb = JOptionPane.showInputDialog("INGRESE Nro DE DESTINOS"); int bbbbbbbbq = Integer.parseInt(bbbbbbbb); l.insertarcabeza(b,bb,bbbq,bbbb,bbbbb,bbbbbb,bbbbbbbq,bbbbbbbbq); vformuaerolineas.setVisible(true); } else { if (e.getActionCommand () == "Aceptar") vformuaerolineas.dispose(); } if (e.getActionCommand () == "Mostrar Aerolineas") { l.visualiza(); // l.visualiza2(); vformuaerolineas.setVisible(true); } else if (e.getActionCommand () == "Ingresar Avion") { String h = JOptionPane.showInputDialog("INGRESE NOMBRE DEL NUEVO AVIÓN"); String hh = JOptionPane.showInputDialog("INGRESE NOMBRE DE AERONAVE"); String hhh = JOptionPane.showInputDialog("INGRESE MOTOR"); String hhhh = JOptionPane.showInputDialog("INGRESE CANTIDAD DE PUESTOS"); int hhhhq = Integer.parseInt(hhhh); String hhhhh = JOptionPane.showInputDialog("INGRESE DESTINOS"); k.insertarcabeza(h,hh,hhh,hhhhq,hhhhh); vformulavion.setVisible(true); } else { if (e.getActionCommand () == "Aceptar") vformulavion.dispose(); } if (e.getActionCommand () == "Mostrar Aviones") { k.visualiza(); vformulavion.setVisible(true); } else if (e.getActionCommand () == "Ingresar Vuelo") { String z = JOptionPane.showInputDialog("INGRESE NOMBRE DE AVION"); String zz = JOptionPane.showInputDialog("INGRESE RUTA"); String zzz = JOptionPane.showInputDialog("INGRESE FECHA DE SALIDA"); String zzzz = JOptionPane.showInputDialog("INGRESE FECHA DE LLEGADA"); String zzzzz = JOptionPane.showInputDialog("INGRESE HORA DE SALIDA"); String zzzzzz = JOptionPane.showInputDialog("INGRESE HORA DE LLEGADA"); String zzzzzzz = JOptionPane.showInputDialog("INGRESE CANTIDAD DE PUESTOS"); int zzzzzzzaq = Integer.parseInt(zzzzzzz); n.insertarcabeza(z,zz,zzz,zzzz,zzzzz,zzzzzz,zzzzzzzaq); } else if (e.getActionCommand () == "Ver Vuelo") { n.visualiza(); } else if (e.getActionCommand() == "Buscar Vuelo") { String Busc = JOptionPane.showInputDialog("Que Ruta Desea Buscar "); Ingresovuelos j = n.Buscar(Busc); // JOptionPane.showInputDialog(null," este es el numero buscado " + j.ruta); // JOptionPane.showInputDialog(null," este es el numero buscado " + l.biscari(Busc)); // System.out.printn(l.biscari(Busc)); // area.append(n.Buscar(Busc)); } } }