The class
class MyComponent extends JComponent {
public void paint(Graphics g) {
g.fillRect(30, 30, 100, 100);
}
}
Jbutton is performed action on this
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jPanel4.add(new MyComponent());
addComponent(new MyComponent());
}
});
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jPanel4.add(new MyComponent1());
addComponent(new MyComponent1());
}
});
I have some other Jbutton action as well . Now I want to detect the shape when it is in the panel. Then I want to perform some action on the panel current shape.
jButton5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jButton1)
{
jPanel4.removeAll();
jPanel4.updateUI();
jPanel4.add(new MyComponent11());
addComponent(new MyComponent11());
}
}
});
But This code is not detecting the shape. Any solution for this please