Howdy, quick question here.
I have a program that will draw 4 squares on the screen with a second smaller square (call this the icon) on 1 of the 4.
I can then drag the icon around and place it on another squares. So I can move it to anyplace I want on these squares. The problem is when I am dragging the icon around, it goes under some of the squares - which is not desired, but over some of them - which is desired.
I looked at the tutorials and it say to use an alpha composite with SRC (or SRC_OVER, too iirc). Here is my paintComponent method:
public void paintComponent(Graphics g)
{
clear(g);
Graphics2D g2d = (Graphics2D)g;
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
for(int i=0;i<idata.length;i++)
{
//place the squares, as buffered images with g2d.drawImage on the screen
}
g2d.draw(square); //this is just a border.
}
When I run this code, no change happens. Sometimes the icon will go over, other times it will go under.
I have a feeling I am missing something here but I am not sure.
Thank you for any help.>