Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. package controlador;
  2. import javax.swing.table.DefaultTableModel;
  3. import modelo.*;
  4. import vista.*;
  5. public class ControladorProducto {
  6. static VentanaProducto ventana = new
  7. VentanaProducto();
  8.  
  9. public static void mostrar(){
  10. ventana.setVisible(true);
  11. cargar();
  12. }
  13. public static void boton1(){
  14. String codigo =
  15. ventana.getjTextField1().getText();
  16. String nombre =
  17. ventana.getjTextField2().getText();
  18. String precio =
  19. ventana.getjTextField3().getText();
  20. Producto p = new Producto();
  21. p.setCodigo(Integer.parseInt(codigo));
  22. p.setNombre(nombre);
  23. p.setPrecio(Double.parseDouble(precio));
  24. DB db = new DB();
  25. db.agregar(p);
  26. cargar();
  27. }
  28. public static void cargar(){
  29. DefaultTableModel datos =
  30. (DefaultTableModel)
  31. ventana.getjTable1().getModel();
  32. datos.setNumRows(0);
  33. for (Producto p : new DB().getProductos()){
  34. Object[] fila = {
  35. p.getCodigo(),
  36. p.getNombre(),
  37. p.getPrecio()
  38. };
  39. datos.addRow(fila);
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement