I currently have a JApplet within which I add two objects that both extend JComponet. Object A is basically a large square and object B is a small square, I need Object B to always be in front of Object A, however I cant work out how to set layering within the JApplet to do this. Current I am using the follow code, which adds both the items and displays them how I want however sometimes Object A is front of Object B.
public void init() {
add(myapplet, BorderLayout.CENTER);
resize(200, 400);
B = new Block(Color.green, 10, 10);
myapplet.add(B);
A = new Block(Color.red, 100, 100);
myapplet.add(A);
myapplet.addMouseListener(this);
startTimer();
}