Pequeños errores
This commit is contained in:
		
							parent
							
								
									92b05fafde
								
							
						
					
					
						commit
						72e3f4fc28
					
				| @ -24,6 +24,10 @@ public class Controlador implements ActionListener{ | |||||||
| 		this.vista.editar.setActionCommand("editar"); | 		this.vista.editar.setActionCommand("editar"); | ||||||
| 		this.vista.mostrarTodo.addActionListener(this); | 		this.vista.mostrarTodo.addActionListener(this); | ||||||
| 		this.vista.mostrarTodo.setActionCommand("mostrar"); | 		this.vista.mostrarTodo.setActionCommand("mostrar"); | ||||||
|  | 		this.vista.eliminar.addActionListener(this); | ||||||
|  | 		this.vista.eliminar.setActionCommand("eliminar"); | ||||||
|  | 		this.vista.buscar.addActionListener(this); | ||||||
|  | 		this.vista.buscar.setActionCommand("buscar"); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| @ -36,10 +40,11 @@ public class Controlador implements ActionListener{ | |||||||
| 			break; | 			break; | ||||||
| 		} | 		} | ||||||
| 		case "editar":{ | 		case "editar":{ | ||||||
| 			this.modelo.modificarTransaccion(this.vista.insertarNombreViejo.getText(), | 			this.modelo.modificarTransaccion(Integer.parseInt(this.vista.insertarNombreViejo.getText()), | ||||||
| 					this.vista.insertarNombre.getText(), | 					this.vista.insertarNombre.getText(), | ||||||
| 					Float.parseFloat(this.vista.insertarDinero.getText()), | 					Float.parseFloat(this.vista.insertarDinero.getText()), | ||||||
| 					this.vista.insertarFecha.getText()); | 					this.vista.insertarFecha.getText()); | ||||||
|  | 			break; | ||||||
| 		} | 		} | ||||||
| 		case "mostrar":{ | 		case "mostrar":{ | ||||||
| 			try { | 			try { | ||||||
| @ -49,7 +54,7 @@ public class Controlador implements ActionListener{ | |||||||
| 				JList<String> lista = new JList<String>(); | 				JList<String> lista = new JList<String>(); | ||||||
| 				Vector<String> elementos = new Vector<String>(); | 				Vector<String> elementos = new Vector<String>(); | ||||||
| 				while(resultado.next()) { | 				while(resultado.next()) { | ||||||
| 					elementos.add(resultado.getString(1) + resultado.getString(2) + resultado.getString(3)); | 					elementos.add(resultado.getString(1) + " " + resultado.getString(2) + " " + resultado.getString(3) + " " + resultado.getString(4)); | ||||||
| 				} | 				} | ||||||
| 				lista.setListData(elementos); | 				lista.setListData(elementos); | ||||||
| 				ventana.add(lista); | 				ventana.add(lista); | ||||||
| @ -58,6 +63,30 @@ public class Controlador implements ActionListener{ | |||||||
| 				// TODO Auto-generated catch block | 				// TODO Auto-generated catch block | ||||||
| 				e1.printStackTrace(); | 				e1.printStackTrace(); | ||||||
| 			} | 			} | ||||||
|  | 			break; | ||||||
|  | 		} | ||||||
|  | 		case "eliminar":{ | ||||||
|  | 			this.modelo.eliminartransaccion(Integer.parseInt(this.vista.insertarNombreViejo.getText())); | ||||||
|  | 			break; | ||||||
|  | 		} | ||||||
|  | 		case "buscar":{ | ||||||
|  | 			try { | ||||||
|  | 				ResultSet resultado = this.modelo.buscarTransaccion(Integer.parseInt(this.vista.insertarNombreViejo.getText())); | ||||||
|  | 				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) + " " + resultado.getString(4)); | ||||||
|  | 				} | ||||||
|  | 				lista.setListData(elementos); | ||||||
|  | 				ventana.add(lista); | ||||||
|  | 				ventana.setVisible(true); | ||||||
|  | 			} catch (SQLException e1) { | ||||||
|  | 				// TODO Auto-generated catch block | ||||||
|  | 				e1.printStackTrace(); | ||||||
|  | 			} | ||||||
|  | 			break; | ||||||
| 		} | 		} | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
|  | |||||||
| @ -1,11 +1,20 @@ | |||||||
| import java.sql.Connection; | import java.sql.Connection; | ||||||
| import java.sql.DriverManager; | import java.sql.DriverManager; | ||||||
| import java.sql.SQLException; | import java.sql.SQLException; | ||||||
|  | import java.util.ResourceBundle.Control; | ||||||
|  | 
 | ||||||
|  | import javax.swing.JFrame; | ||||||
| 
 | 
 | ||||||
| public class Main { | public class Main { | ||||||
| 
 | 
 | ||||||
| 	public static void main(String[] args) { | 	public static void main(String[] args) { | ||||||
|  | 		Vista vista = new Vista(); | ||||||
| 		Modelo modelo = new Modelo(); | 		Modelo modelo = new Modelo(); | ||||||
|  | 		Controlador controlador = new Controlador(vista, modelo); | ||||||
|  | 		JFrame frame = new JFrame(); | ||||||
|  | 		frame.setSize(200, 500); | ||||||
|  | 		frame.add(vista); | ||||||
|  | 		frame.setVisible(true); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -57,12 +57,12 @@ public class Modelo { | |||||||
| 		return ret; | 		return ret; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public void eliminartransaccion(String nombre) { | 	public void eliminartransaccion(int id) { | ||||||
| 		String query ="delete from transacciones" +  | 		String query ="delete from transacciones " +  | ||||||
| 				"where nombre=?;";  | 				"where id=?;";  | ||||||
| 		try { | 		try { | ||||||
| 			PreparedStatement stmt = this.connection.prepareStatement(query); | 			PreparedStatement stmt = this.connection.prepareStatement(query); | ||||||
| 			stmt.setString(1, nombre); | 			stmt.setInt(1, id); | ||||||
| 			stmt.executeUpdate(); | 			stmt.executeUpdate(); | ||||||
| 		} catch (SQLException e) { | 		} catch (SQLException e) { | ||||||
| 			// TODO Auto-generated catch block | 			// TODO Auto-generated catch block | ||||||
| @ -70,30 +70,31 @@ public class Modelo { | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public void modificarTransaccion(String nombreViejo, String nombre, float dinero, String fecha) { | 	public void modificarTransaccion(int id, String nombre, float dinero, String fecha) { | ||||||
| 		String query ="update transacciones" +  | 		String query ="update transacciones " +  | ||||||
| 				"set nombre=?, dinero=?, fecha=?"+ | 				"set nombre=?, dinero=?, fecha=? "+ | ||||||
| 				"where nombre=?;"; | 				"where id=?;"; | ||||||
| 		try { | 		try { | ||||||
| 			PreparedStatement stmt = this.connection.prepareStatement(query); | 			PreparedStatement stmt = this.connection.prepareStatement(query); | ||||||
| 			stmt.setString(1, nombre); | 			stmt.setString(1, nombre); | ||||||
| 			stmt.setFloat(2, dinero); | 			stmt.setFloat(2, dinero); | ||||||
| 			stmt.setString(3, fecha); | 			stmt.setString(3, fecha); | ||||||
| 			stmt.setString(4, nombreViejo); | 			stmt.setInt(4, id); | ||||||
|  | 			stmt.executeUpdate(); | ||||||
| 		} catch (SQLException e) { | 		} catch (SQLException e) { | ||||||
| 			// TODO Auto-generated catch block | 			// TODO Auto-generated catch block | ||||||
| 			e.printStackTrace(); | 			e.printStackTrace(); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public ResultSet buscarTransaccion(String nombre) { | 	public ResultSet buscarTransaccion(int id) { | ||||||
| 		String query = "select * " +  | 		String query = "select * " +  | ||||||
| 				"from transacciones" +  | 				"from transacciones " +  | ||||||
| 				"where nombre=?;"; | 				"where id=?;"; | ||||||
| 		ResultSet ret = null;  | 		ResultSet ret = null;  | ||||||
| 		try { | 		try { | ||||||
| 			PreparedStatement stmt = this.connection.prepareStatement(query); | 			PreparedStatement stmt = this.connection.prepareStatement(query); | ||||||
| 			stmt.setString(1, nombre); | 			stmt.setInt(1, id); | ||||||
| 			ret = stmt.executeQuery(); | 			ret = stmt.executeQuery(); | ||||||
| 		} catch (SQLException e) { | 		} catch (SQLException e) { | ||||||
| 			// TODO Auto-generated catch block | 			// TODO Auto-generated catch block | ||||||
|  | |||||||
| @ -15,6 +15,8 @@ public class Vista extends JPanel{ | |||||||
| 	JButton mostrarTodo; | 	JButton mostrarTodo; | ||||||
| 	JButton aniadir; | 	JButton aniadir; | ||||||
| 	JButton editar; | 	JButton editar; | ||||||
|  | 	JButton eliminar; | ||||||
|  | 	JButton buscar; | ||||||
| 	JTextField textoNombreViejo; | 	JTextField textoNombreViejo; | ||||||
| 	JTextField insertarNombreViejo; | 	JTextField insertarNombreViejo; | ||||||
| 	 | 	 | ||||||
| @ -28,50 +30,57 @@ public class Vista extends JPanel{ | |||||||
| 		this.add(this.textoNombre, constrain); | 		this.add(this.textoNombre, constrain); | ||||||
| 		this.textoDinero = new JTextField("dinero"); | 		this.textoDinero = new JTextField("dinero"); | ||||||
| 		this.textoDinero.setEditable(false); | 		this.textoDinero.setEditable(false); | ||||||
| 		constrain.gridx = 1; | 		constrain.gridx = 0; | ||||||
| 		constrain.gridy = 0; | 		constrain.gridy = 1; | ||||||
| 		this.add(this.textoDinero, constrain); | 		this.add(this.textoDinero, constrain); | ||||||
| 		this.textoFecha = new JTextField("fecha"); | 		this.textoFecha = new JTextField("fecha"); | ||||||
| 		this.textoFecha.setEditable(false); | 		this.textoFecha.setEditable(false); | ||||||
| 		constrain.gridx = 2; | 		constrain.gridx = 0; | ||||||
| 		constrain.gridy = 0; | 		constrain.gridy = 2; | ||||||
| 		this.add(this.textoFecha, constrain); | 		this.add(this.textoFecha, constrain); | ||||||
| 		 | 		 | ||||||
| 		this.insertarNombre = new JTextField("nombre"); | 		this.insertarNombre = new JTextField("nombre"); | ||||||
| 		constrain.gridx = 0; | 		constrain.gridx = 1; | ||||||
| 		constrain.gridy = 1; | 		constrain.gridy = 0; | ||||||
| 		this.add(this.insertarNombre, constrain); | 		this.add(this.insertarNombre, constrain); | ||||||
| 		this.insertarDinero = new JTextField("dinero"); | 		this.insertarDinero = new JTextField("dinero"); | ||||||
| 		constrain.gridx = 1; | 		constrain.gridx = 1; | ||||||
| 		constrain.gridy = 1; | 		constrain.gridy = 1; | ||||||
| 		this.add(this.insertarDinero, constrain); | 		this.add(this.insertarDinero, constrain); | ||||||
| 		this.insertarFecha = new JTextField("fecha"); | 		this.insertarFecha = new JTextField("fecha"); | ||||||
| 		constrain.gridx = 2; | 		constrain.gridx = 1; | ||||||
| 		constrain.gridy = 1; | 		constrain.gridy = 2; | ||||||
| 		this.add(this.insertarFecha, constrain); | 		this.add(this.insertarFecha, constrain); | ||||||
| 		 | 		 | ||||||
| 		this.aniadir = new JButton("aniadir"); | 		this.aniadir = new JButton("aniadir"); | ||||||
| 		constrain.gridx = 0; | 		constrain.gridx = 0; | ||||||
| 		constrain.gridy = 2; | 		constrain.gridy = 3; | ||||||
| 		this.add(this.aniadir, constrain); | 		this.add(this.aniadir, constrain); | ||||||
| 		this.editar = new JButton("editar"); | 		this.editar = new JButton("editar"); | ||||||
| 		constrain.gridx = 1; | 		constrain.gridx = 1; | ||||||
| 		constrain.gridy = 2; | 		constrain.gridy = 3; | ||||||
| 		this.add(this.editar, constrain); | 		this.add(this.editar, constrain); | ||||||
| 		this.mostrarTodo = new JButton("mostrar todo"); | 		this.mostrarTodo = new JButton("mostrar todo"); | ||||||
| 		constrain.gridx = 2; | 		constrain.gridx = 2; | ||||||
| 		constrain.gridy = 2; | 		constrain.gridy = 3; | ||||||
| 		this.add(this.mostrarTodo, constrain); | 		this.add(this.mostrarTodo, constrain); | ||||||
| 		 | 		this.eliminar = new JButton("eliminar"); | ||||||
| 		this.textoNombreViejo = new JTextField("nombre a cabiar"); |  | ||||||
| 		this.textoNombre.setEditable(false); |  | ||||||
| 		constrain.gridx = 3; | 		constrain.gridx = 3; | ||||||
| 		constrain.gridy = 0; | 		constrain.gridy = 3; | ||||||
|  | 		this.add(eliminar, constrain); | ||||||
|  | 		this.buscar = new JButton("buscar"); | ||||||
|  | 		constrain.gridx = 4; | ||||||
|  | 		constrain.gridy = 3; | ||||||
|  | 		this.add(buscar, constrain); | ||||||
|  | 		 | ||||||
|  | 		this.textoNombreViejo = new JTextField("id a cabiar"); | ||||||
|  | 		this.textoNombreViejo.setEditable(false); | ||||||
|  | 		constrain.gridx = 0; | ||||||
|  | 		constrain.gridy = 4; | ||||||
| 		this.add(this.textoNombreViejo, constrain); | 		this.add(this.textoNombreViejo, constrain); | ||||||
| 
 | 		this.insertarNombreViejo = new JTextField("id a cambiar"); | ||||||
| 		this.insertarNombreViejo = new JTextField("nombre a cambiar"); | 		constrain.gridx = 1; | ||||||
| 		constrain.gridx = 3; | 		constrain.gridy = 4; | ||||||
| 		constrain.gridy = 1; |  | ||||||
| 		this.add(this.insertarNombreViejo, constrain); | 		this.add(this.insertarNombreViejo, constrain); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user