java - JFrame freezes while running the code continuously -


I have a problem while working with JFrame , which would be frozen during continuous code running When I click on :

  1. BTNRun , I've called the function menuup () :

      Executioner btnRun_Click = New Executioner () {@ Override Public Voice Action Crore (Action Event E) {ManLow (); }};    
  2. Implementing MainLoop () :

      void MainLoop () {hopper = new chopper ( this); Println (Hooper); BtnRun.setEnabled (wrong); TextBox1.setText (""); Hopper.getM_cmd () ComPort = helpers.Global.ComPort; Hopper.getM_cmd () SSPAddress = helpers.Global.SSPAddress; Hopper.getM_cmd () Timeout = 2000; Hopper.getM_cmd () RetryLevel = 3; System.out.println ("In the Main Loop:" + Hopper); // First connect to the valuer if (connectiveleader (10, 3)) {btnHalt.setEnabled (true); Running = true; Textbox1.append ("\ r \ nPole Loop \ r \ n" + "*************************************************** ******************************************************************);); } // This loop will not work until the verifier is connected (Running) {// If the voter becomes valid (! Hopper. Dopple (text box 1)) // If the voting fails, Try adding the text box 1 .append ("Try reconnecting ... \ r \ n"); If (! ConnectToValidator (10, 3)) {// If it fails after 5 attempts, then the running loop = false; }} // Ticker Timer // Timer 1. Start (); // UpdateUI () Update; // Once Set Up Dynamic Elements of the Win Form (! BFormSetup) {SetupFormLayout (); BFormSetup = true; }} // Off Com Port Hopper.getM_eSSP (). CloseComPort (); BtnRun.setEnabled (true); BtnHalt.setEnabled (wrong); }    
  3. In the mainloo () function, running the loop, until the actual problem is running, I stop the loop I have to set false running which is done on any other button btnHalt :

      ActionListener btnHalt_Click = new ActionListener () {@Override Public Zero Action (Action Event e) {textBox1.append ("polling loop paused \ r \ n"); System.out.println ("Hopper Stop"); Running = Wrong; }};       

    but btnHalt is not responding, the whole frame is freezed, too textarea .

    Swing is a thread structure, that is, the paint request to send all the components to all components Including a single thread is responsible for sending.

    Any work that stops / blocks, this thread will be caused by "hang" your UI.

    The first rule of swing, never , instead of running a blocked or time consuming task on the event despatches thread, you should use the background thread.

    It runs you swing in the second rule of swing. Never create, modify, or interact with any UI components outside the EDT.

    You can fix it. You can use SwingUtilities.invokeLater or swingwalker .

    Swingwalker is normally simple, because it provides a lot of simple

    updated < P> To read through

    just like you understand;)

    Your main loop method should not be executed in the context of EDT It's too bad, it's too bad.

    In addition, you should not interact with any UI element from any thread, with EDT.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -