How can I check that JButton is pressed? If the isEnable() is not work?

前端 未结 6 1551
Happy的楠姐
Happy的楠姐 2020-11-30 14:22

How can I check that JButton is pressed? I know that there is a method that its name is \"isEnabled\"

So I try to write a code to test.

  1. this code have
6条回答
  •  误落风尘
    2020-11-30 14:44

    The method you are trying to use checks if the button is active:

    btnAdd.isEnabled()

    When enabled, any component associated with this object is active and able to fire this object's actionPerformed method.

    This method does not check if the button is pressed.

    If i understand your question correctly, you want to disable your "Add" button after the user clicks "Check out".

    Try disabling your button at start: btnAdd.setEnabled(false) or after the user presses "Check out"

提交回复
热议问题