I want to check the event of panel class which is being added on the JFrame
class. In this sample program there is a button on a panel.
I want to monitor the click event of the button from the source frame.
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
class test extends JFrame implements ActionListener {
test() {
Container cp = this.getContentPane();
JButton b1 = new JButton("add");
cp.add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getActionCommand().equals("add")) {
panel1 frm = new panel1();
cp.add(frm);
}
}
public static void main(String args[]) {
test t1 = new test();
t1.show(true);
}
}
class panel1 extends JPanel {
panel1() {
JButton b1 = new JButton("ok");
add(b1);
}
}