I am trying to receive the selected option from a custom JFrame in Java. The code works fine as expected when running in debug mode in netbeans (when there is a breakpoint inside the loop) but not in real time.
boolean keepgoing = true;
while (keepgoing) {
if (ioFrame.getOption() == 0) {
ioFrame.setVisible(false);
keepgoing = false;
//more code
}
else if (ioFrame.getOption() == 1) {
ioFrame.setVisible(false);
keepgoing = false;
//more code
}
}
ioFrame.getOption()
returns -1 until a button is clicked on the JFrame, then depending on the button clicked it is either 0 or 1.
ioFrame Action Listeners:
JButton loadButton = new JButton("Load Inventory");
class ChoiceListener implements ActionListener
{
@Override
public void actionPerformed(ActionEvent event)
{
initialOption = 0;
}
}
loadButton.addActionListener(new ChoiceListener());
JButton updateButton = new JButton("Update Inventory");
class ChoiceListener2 implements ActionListener
{
@Override
public void actionPerformed(ActionEvent event)
{
initialOption = 1;
}
}
updateButton.addActionListener(new ChoiceListener2());