-1

I have a swing GUI, I'm trying to get my GUI to close if a certain requirement is met only if the checkbox is checked JCheckBox C1 = new JCheckBox("checkbox 1"); so the code should be something like if(Jcheckbox is pressed) //do something

if that makes sense

0xh3xa
  • 4,801
  • 2
  • 14
  • 28
Svoklavok
  • 11
  • 2

1 Answers1

2

Try this:

if(c1.isSelected()){
    // your code
}

or use event if you want to do some action when the selection happens

myCheckBox.addItemListener((ItemEvent e) {
        if(e.getStateChange() == ItemEvent.SELECTED) {
            //do something...
        } else {//checkbox has been deselected
            //do something...
        }
    }
});

0xh3xa
  • 4,801
  • 2
  • 14
  • 28
  • hey this helped thanks, but how would i do this? if (C1.isSelected()&&t1.getText()>=350){ System.exit(1); } how would i do this? – Svoklavok Mar 22 '20 at 15:38
  • if(C1.isSelected() && t1.getText() != null &&t1.getText().length() >= 350) { System.exit(1); } – 0xh3xa Mar 22 '20 at 15:40