Q:

use actionlistener to call void function in same class

I have problem to use action listener to call function void in same class.
example..
code:
public class Product extends JPanel {

    JButton add;
    JPanel pAdd;
    JLabel test;
    JFrame frame;

    public Product() {
        add = new JButton("Add Product");
        add.addActionListener(new ButtonListener());

        add(add);
    }

    public void panelAdd(){
        pAdd = new JPanel();
        pAdd.add(new JLabel("try"));
        add(pAdd);

    }

    private class ButtonListener implements ActionListener {
        public void actionPerformed(ActionEvent event) {
            panelAdd();
        }
    }
}

How to make call the panelAdd void method?

A:

When you add components to visible JFrame/JPanel/other components, you neet to call revalidate() andrepaint() methods after adding. Change your panelAdd() like next:
public void panelAdd(){
    pAdd = new JPanel();
    pAdd.add(new JLabel("try"));
    add(pAdd);
    revalidate();
    repaint();
}

