For the current project, we only need to allow the user to press the button once every 5 or so seconds. We use the button to start the print job, but we need to stop users from the spam button and start a dozen print jobs.
We are currently trying to use the following code, but it seems to push the buttons even when the button is disabled. Therefore, after a 5-second delay, clicks are recorded even hard at this time when the button is disabled.
private void Button1ActionPerformed(java.awt.event.ActionEvent evt) { Button1.setEnabled(false); pressCount++; System.out.println("Press count: " + pressCount); PrintJob print = new PrintJob(); try { Thread.sleep(5000); } catch (InterruptedException ex) { Logger.getLogger(GUIFrame.class.getName()).log(Level.SEVERE, null, ex); } try { print.PrintJob(); } catch (IOException ex) { Logger.getLogger(GUIFrame.class.getName()).log(Level.SEVERE, null, ex); } }
source share