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