0

I am working on a java swing project and I have a frame with multiple buttons and when someone clicks any of that button,user is asked for an input(say the user enters n) and a new frame is created with n text fields with another button "Ok" {new frame is created inside the actionPerformed method.So my question is how to handle the action events for this Ok button.I tried using an anonymous class but I can't do much with variables inside it. Source File:http://www.mediafire.com/file/9ed2h0yeyis5tk6/OSProject.txt

  • 1
    you could use object property for cancelling the loop... – JohnnyAW Dec 20 '17 at 20:37
  • `while(Bursttime[0]==-1) //Infinite Loop and it will run untill Ok is pressed` this is not true, it doesn't work this way, you shouldn't even get the opportunity to click on the button to call your action listener, because your while-loop is blocking the main Thread at this point – JohnnyAW Dec 20 '17 at 20:41
  • 1
    1) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). (And post it here, not at some external link that most will not follow.) 2) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Dec 21 '17 at 00:06

1 Answers1

1
  1. Use a modal JDialog or JOptionPane. See How to Make Dialogs
  2. Define the functionality for the second window within it's own class, so you can isolate the functionality and management in more easily manageable manner. Provide setters and getters to allow information to passed between it and the class which needs to use it. If you're using a JOptionPane, this step makes it easier to define a custom component which can be displayed by it
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366