我有一个 JTogglebuttons 数组和一个 JButton,当按下 JButton 时它会启动一个循环,该循环遍历所有 JTogglebuttons 以查看它是否被按下,如果是它应该使其禁用/不可点击
这是有问题的代码片段
Public void actionPerformed(ActionEvent e){
Object pressed = e.getSource();
if (pressed == btnPurchase) {
for(int row = 0; row<8 ; row++){
for(int column = 0; column < 4; column++) {
if (seat[row][column].isPressed()) {
seat[row][column].setEnabled(false);
}
}
}
}
我收到这个错误
cannot find symbol
symbol : method isPressed()
location: class javax.swing.JToggleButton
if (seat[row][column].isPressed()) {
如果我使用 .isSelected
我明白了
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at cinemaManager.actionPerformed(cinemaManager.java:174)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6375)