gpt4 book ai didi

java - mouseClicked 事件无法正常工作

转载 作者:行者123 更新时间:2023-12-01 13:40:30 27 4
gpt4 key购买 nike

 private JTable getTRent() {
if (tRent == null) { ...

tRent.addMouseListener(new MouseAdapter() {

@Override
public void mouseClicked(MouseEvent arg0) {
tDescription.setText(house.getDescripcionMansion(tRent.getSelectedRow()));

image.setIcon(new ImageIcon(BookWindow.class.getResource(
"/images/" + house.getCodeMansion(tRent.getSelectedRow()) + ".png")));

String childrenAllowed = house.getChildrenAllowed(tRent.getSelectedRow());

if (childrenAllowed == "N"){
txKids.setEditable(false);
cbBookHouse.setEnabled(true);
}

}
});
}
return tRent;
}

我在前面的代码中遇到的问题是,除了图像之外的任何条件都已完成,似乎都被忽略了。

我刚刚检查了该值是否已正确读取,并且在控制台中使用 println 时,我会根据行得到 N 或 Y,但是如果我检查该值,则不会发生任何情况我希望更改其状态的组件。

还尝试将这些条件放入组件内,并且发生了同样的情况。

例如方法getChildrenAllowed()的代码是这样的

      public String getChildrenAllowed(int index) {
return houseRelation.get(index).getChildren();
}

最佳答案

不要将字符串与 == 进行比较,而使用 equals()equalsIgnoreCase()

if ("N".equalsIgnoreCase(childrenAllowed))

参见How do I compare Strings in Java

关于java - mouseClicked 事件无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20840762/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com