我试着写一个gui,它会根据mouseClick改变标签。我实现了一个点击和拖动系统,但问题是它只在全屏时才有效?任何人都可以告诉我如何使我的点相对于框架?基本上,我的JLabels位置已关闭,我需要它来匹配面板而不是屏幕:
int xbegin = 0, ybegin = 0, xend, yend= 0;
Point px, p2x = null;
for(int a = 0; a < states.size(); a++ ){
if(states.get(a).getIcon() == yellowIcon){
self = true;
xbegin = states.get(a).getX();
ybegin = states.get(a).getY();
p2x = (SwingUtilities.convertPoint(states.get(a), xbegin, ybegin, jPanel2));
states.get(a).setIcon(rectangleIcon);
yellow = false;
}
else if(states.get(a).getIcon() == yellow2Icon){
System.out.println("this is zarir");
xend = states.get(a).getX();
yend = states.get(a).getY();
px = (SwingUtilities.convertPoint(states.get(a), xend, yend, jPanel2));
Shape rect = new Rectangle2D.Double(p2x.x,60,px.x-p2x.x,2);
ShapeIcon transit = new ShapeIcon(rect, Color.red);
JLabel transitLabel = new JLabel(transit);
transition.add(transitLabel);
transitLabel.setText("Define Transition");
transitLabel.setBounds(p2x.x,70,px.x-p2x.x, 200);
System.out.println(transitLabel.getBounds());
states.get(a).setIcon(rectangleIcon);
jPanel2.add(transitLabel);
jPanel2.revalidate();
jPanel2.repaint();
}
}
}
我每次点击我的面板时都会得到mouseCoordinates但是当我点击我的标签时我没有收到任何坐标?一般来说,GUI的任何提示都会非常有用