My Mouse Released is not working. In my code there are two JPanels(p1 and p2) in another JPanel(p). and there are two Buttons named RED and GREEN. My Code should work like when someone click the Buttons, The Panels should be changed Dynamically . But unfortunately When I am running my program, the Button "RED" and "GREEN" is not responding. Here I have Added my codes. Thank you.
package animat;
import java.awt.Color;
import java.awt.event.*;
import javax.swing.*;
public class Animat extends JFrame{
Animat(){
JFrame j=new JFrame();
j.setSize(400,400);
j.setVisible(true);
JPanel p=new JPanel();
p.setSize(300,400);
p.setLayout(null);
p.setBackground(Color.BLACK);
p.setVisible(true);
j.add(p);
JPanel p1=new JPanel();
p1.setBounds(0,50,400,350);
p1.setBackground(Color.red);
p1.setVisible(true);
p.add(p1);
JPanel p2=new JPanel();
p2.setBounds(0,50,400,350);
p2.setBackground(Color.GREEN);
p2.setVisible(true);
p.add(p2);
JButton b=new JButton("RED");
b.setBounds(0,0,100,50);
b.setVisible(true);
p.add(b);
JButton b1=new JButton("GREEN");
b1.setBounds(100,0,100,50);
b1.setVisible(true);
p.add(b1);
b.addMouseListener(new MouseAdapter(){
public void MouseReleased(MouseEvent e){
p.removeAll();
p.repaint();
p.revalidate();
p.add(p1);
}
});
b1.addMouseListener(new MouseAdapter(){
public void MouseReleased(MouseEvent e){
p.removeAll();
p.repaint();
p.revalidate();
p.add(p2);
}
});
}
public static void main(String[] args) {
new Animat();
}
}