import javax.swing.*;
import java.awt.*;
class drawer extends JPanel
{ Color color;
int x;
drawer(int x,Color color){
this.color=color;//color of rectangle
this.x=x;//size
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawRect(0,0,x,x);
g.setColor(color);
g.fillRect(0,0,x,x);
}
}
public class layers {
public static void main(String[] args) {
JLayeredPane layerd=new JLayeredPane();
layerd.setSize(800,800);
layerd.setVisible(true);
layerd.add(new drawer(50,Color.BLUE),2);
layerd.validate();
layerd.add(new drawer(70,Color.red),1);
layerd.validate();
JFrame frame=new JFrame();
frame.setVisible(true);
frame.setSize(800,800);
frame.add(layerd);
frame.setResizable(false);
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
}
}
it displays nothing am i missing something.