public Textures()
{
super(new GridBagLayout());
layout.add(l1);
layout.add(l2);
add(layout);
String[] T = filerw.fileRead2();
if(T[0].equals("11"))
{
rect1.setLocation(layout.getComponent(1).getBounds().getLocation());
}
if(T[0].equals("12"))
{
rect1.setLocation(layout.getComponent(2).getBounds().getLocation());
}
l1.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent arg0)
{
a = 11;
filerw.fileWrite();
rect1.setLocation(l1.getBounds().getLocation().x, l1.getBounds().getLocation().y);
}
});
l2.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent arg0)
{
a = 12;
filerw.fileWrite();
rect1.setLocation(l2.getBounds().getLocation().x, l2.getBounds().getLocation().y);
repaint();
}
});
I have tried many ways to ind the location of a component, and they all either get an error, turn up as zero, or the incorrect location. I have tried getX() and x, getBounds.getLocation, getLocation, getLocationOnScreen, layout.getComponent(1) or l1. How do I find the location of a component? I am tring to get a rectangle to surround the image, how do I accomplish the location?
I have answered this question by using a Border instead of a Rectangle. Thanks you trashgod!
If you are reading this to answer a questions, look at the comments above.