0
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();
        }
    });

コンポーネントの場所を特定するために多くの方法を試しましたが、すべてエラーが発生するか、ゼロになるか、場所が正しくありません。getX() と x、getBounds.getLocation、getLocation、getLocationOnScreen、layout.getComponent(1) または l1 を試しました。コンポーネントの場所を見つけるにはどうすればよいですか? 画像を囲む四角形を取得しようとしていますが、その場所をどのように設定すればよいですか?

4

1 に答える 1

0

長方形の代わりに境界線を使用してこの質問に答えました。trashgodありがとう!

質問に答えるためにこれを読んでいる場合は、上のコメントを見てください。

于 2012-09-05T21:10:01.290 に答える