简体   繁体   English

如果将标签移至特定坐标,该怎么办?

[英]How do I do something if a label is moved to a certain cordinates?

I am using label.setLocation(x,y) and I was wondering how do I do something if the label goes to a certain x or y coordinate? 我正在使用label.setLocation(x,y) ,我想知道如果标签到达某个xy坐标该怎么办? Please make the code understandable and pretty simple since I don't want to get anymore confused that I am right now :) Thank you. 请使代码易于理解并且非常简单,因为我不想再对我现在感到困惑了:)谢谢。

The easiest solution would be to create your own label and override the setLocation method: 最简单的解决方案是创建您自己的标签并覆盖setLocation方法:

public class MyLabel extends JLabel {
    @Override
    public void setLocation(int x, int y) {
        super.setLocation(x, y);

        //Check the X and Y and do something accordingly.
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM