There are 2 frames. On one there is a table, on the other - a button. Required when you click on the button add to the table entry. They say: “use ActionListener”, but I don’t even have an idea how it should look. Can I have a code sample?
Frame1:
public class Frame1 extends javax.swing.JFrame { DefaultTableModel data = new DefaultTableModel(); public Frame1() { initComponents(); data.addColumn("A"); data.addColumn("B"); jTable1.setModel(data); }
Frame2:
public class Frame2 extends javax.swing.JFrame { Frame1 fr; public Frame2(final Frame1 fr) { this.fr = fr; initComponents(); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { fr.data.addRow(new Object[] {1, 2}); } }); }
MainClass:
public class MainClass { public static void main(String[] args) { new Frame1().setVisible(true); new Frame2(new Frame1()).setVisible(true); } }