Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package controlador;
- import javax.swing.table.DefaultTableModel;
- import modelo.*;
- import vista.*;
- public class ControladorProducto {
- static VentanaProducto ventana = new
- VentanaProducto();
- public static void mostrar(){
- ventana.setVisible(true);
- cargar();
- }
- public static void boton1(){
- String codigo =
- ventana.getjTextField1().getText();
- String nombre =
- ventana.getjTextField2().getText();
- String precio =
- ventana.getjTextField3().getText();
- Producto p = new Producto();
- p.setCodigo(Integer.parseInt(codigo));
- p.setNombre(nombre);
- p.setPrecio(Double.parseDouble(precio));
- DB db = new DB();
- db.agregar(p);
- cargar();
- }
- public static void cargar(){
- DefaultTableModel datos =
- (DefaultTableModel)
- ventana.getjTable1().getModel();
- datos.setNumRows(0);
- for (Producto p : new DB().getProductos()){
- Object[] fila = {
- p.getCodigo(),
- p.getNombre(),
- p.getPrecio()
- };
- datos.addRow(fila);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement