How to move a matrix from one JFrame to another JFrame in Netbeans?

0

I have a matrix in a jFrame in which I capture the data, when I click on a button of that frame, I have to open a second window where I show the matrix captured inside a table, the problem is that I do not know how To do it, I tried the method of using variables in both frames but it does not work. Thanks in advance.

    
asked by Mip ́s Trash. 02.11.2016 в 19:06
source

1 answer

0

public static class Form1 extends JFrame {

    private JButton btn;

    public Formulario1() {
        super("Llamada");

        btn = new JButton("Llamar");

        setLayout(new BorderLayout());
        add(btn, BorderLayout.CENTER);
        setSize(100, 100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        btn.addActionListener((ActionEvent ae) -> {
            final Formulario2 frm = new Formulario2(new Object[]{"Dato1", "Dato2", "Dato3", 15});
            frm.setVisible(true);
        });

        setVisible(true);
    }
}

public static class Formulario2 extends JFrame {

    private Object[] arr;

    private JList lst;
    private DefaultListModel mdl;

    public Formulario2(Object[] arr) {
        super();

        this.arr = arr;

        lst = new JList();
        mdl = new DefaultListModel();

        lst.setModel(mdl);

        add(lst);
        mostrarDatos();
    }

    public void mostrarDatos() {
        if (arr != null && arr.length > 0) {
            for (int i = 0; i < arr.length; i++) {
                mdl.addElement(arr[i].toString());
            }
        }
    }
}

}

    
answered by 03.11.2016 / 22:40
source