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

前端 未结 6 1524
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:50

    JButton has a model which answers these question:

    • isArmed(),
    • isPressed(),
    • isRollOVer()

    etc. Hence you can ask the model for the answer you are seeking:

         if(jButton1.getModel().isPressed())
            System.out.println("the button is pressed");
    

提交回复
热议问题