aniadir controlador
This commit is contained in:
		
							parent
							
								
									bb7282ce44
								
							
						
					
					
						commit
						92b05fafde
					
				@ -1,4 +1,65 @@
 | 
				
			|||||||
 | 
					import java.awt.event.ActionEvent;
 | 
				
			||||||
 | 
					import java.awt.event.ActionListener;
 | 
				
			||||||
 | 
					import java.sql.ResultSet;
 | 
				
			||||||
 | 
					import java.sql.SQLException;
 | 
				
			||||||
 | 
					import java.util.Vector;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class Controlador {
 | 
					import javax.swing.JFrame;
 | 
				
			||||||
 | 
					import javax.swing.JList;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class Controlador implements ActionListener{
 | 
				
			||||||
 | 
						Vista vista;
 | 
				
			||||||
 | 
						Modelo modelo;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public Controlador(Vista vista, Modelo modelo) {
 | 
				
			||||||
 | 
							this.vista = vista;
 | 
				
			||||||
 | 
							this.modelo = modelo;
 | 
				
			||||||
 | 
							this.anaidirListeners();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private void anaidirListeners() {
 | 
				
			||||||
 | 
							this.vista.aniadir.addActionListener(this);
 | 
				
			||||||
 | 
							this.vista.aniadir.setActionCommand("aniadir");
 | 
				
			||||||
 | 
							this.vista.editar.addActionListener(this);
 | 
				
			||||||
 | 
							this.vista.editar.setActionCommand("editar");
 | 
				
			||||||
 | 
							this.vista.mostrarTodo.addActionListener(this);
 | 
				
			||||||
 | 
							this.vista.mostrarTodo.setActionCommand("mostrar");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Override
 | 
				
			||||||
 | 
						public void actionPerformed(ActionEvent e) {
 | 
				
			||||||
 | 
							switch(e.getActionCommand()) {
 | 
				
			||||||
 | 
							case "aniadir":{
 | 
				
			||||||
 | 
								this.modelo.insertarTransaccion(this.vista.insertarNombre.getText(),
 | 
				
			||||||
 | 
										Float.parseFloat(this.vista.insertarDinero.getText()),
 | 
				
			||||||
 | 
										this.vista.insertarFecha.getText());
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							case "editar":{
 | 
				
			||||||
 | 
								this.modelo.modificarTransaccion(this.vista.insertarNombreViejo.getText(),
 | 
				
			||||||
 | 
										this.vista.insertarNombre.getText(),
 | 
				
			||||||
 | 
										Float.parseFloat(this.vista.insertarDinero.getText()),
 | 
				
			||||||
 | 
										this.vista.insertarFecha.getText());
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							case "mostrar":{
 | 
				
			||||||
 | 
								try {
 | 
				
			||||||
 | 
									ResultSet resultado = this.modelo.obtenerTransacciones();
 | 
				
			||||||
 | 
									JFrame ventana = new JFrame();
 | 
				
			||||||
 | 
									ventana.setSize(200, 200);
 | 
				
			||||||
 | 
									JList<String> lista = new JList<String>();
 | 
				
			||||||
 | 
									Vector<String> elementos = new Vector<String>();
 | 
				
			||||||
 | 
									while(resultado.next()) {
 | 
				
			||||||
 | 
										elementos.add(resultado.getString(1) + resultado.getString(2) + resultado.getString(3));
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									lista.setListData(elementos);
 | 
				
			||||||
 | 
									ventana.add(lista);
 | 
				
			||||||
 | 
									ventana.setVisible(true);
 | 
				
			||||||
 | 
								} catch (SQLException e1) {
 | 
				
			||||||
 | 
									// TODO Auto-generated catch block
 | 
				
			||||||
 | 
									e1.printStackTrace();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user