如何在使用mouseadapter时获取第一个数据?

f45qwnt8  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(341)

我想做的代码,当我按下左上区域,矩形选择和调整大小它使用拖放(右下是固定的,使用左上点调整大小)。

class MyMouseListener extends MouseAdapter {
    public void mousePressed(MouseEvent e) {
        start = e.getPoint();
        if((up.a<start.x&&start.x<up.a+10&&up.b<start.y&&start.y<up.b+10)) {//When I pressed Rectangle's left up area
            Label.setText("up");
            if(tempshape==null) {
                tempshape=shapes.get(now);
            }
            ud=1;
        }
``` `tempshape` 是一个全局变量,我只想得到第一个数据 `tempshape` 作为:

shape tempshape=null;
if(ud==1) {
else if(nowshape=="Rectangle") {
shapes.get(now).setA(end.x);
shapes.get(now).setB(end.y);
shapes.get(now).setC(tempshape.c+end.x);
shapes.get(now).setD(tempshape.d+end.y);
}
} ]

但是tempshape在我拖动时仍然更新它的值,以便从中获取垃圾数据 `tempshape` . 我想知道:
为什么? `tempshape` 正在拖动时更新(我只写 `tempshape` 中的更新代码。)
我怎样才能解决这个问题?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题