JFrame freezes while running the code continuously

I have problem while working with `JFrame`, which get freezes while running the code continuously. Below is my code: 1. On clicking on `btnRun`, I called the function `MainLoop()`: ActionListener btnRun_Click = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { MainLoop(); } }; 2. Implementation of `MainLoop()`: void MainLoop() { Hopper = new CHopper(this); System.out.println(Hopper); btnRun.setEnabled(false); 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 MainLoop: " + Hopper); // First connect to the validator if (ConnectToValidator(10, 3)) { btnHalt.setEnabled(true); Running = true; textBox1.append("\r\nPoll Loop\r\n" + "*********************************\r\n"); } // This loop won't run until the validator is connected while (Running) { // poll the validator if (!Hopper.DoPoll(textBox1)) { // If the poll fails, try to reconnect textBox1.append("Attempting to reconnect...\r\n"); if (!ConnectToValidator(10, 3)) { // If it fails after 5 attempts, exit the loop Running = false; } } // tick the timer // timer1.start(); // update form UpdateUI(); // setup dynamic elements of win form once if (!bFormSetup) { SetupFormLayout(); bFormSetup = true; } } //close com port Hopper.getM_eSSP().CloseComPort(); btnRun.setEnabled(true); btnHalt.setEnabled(false); } 3. In the `MainLoop()` function, the while loop is running continuesly until the Running is true problem is that if i want to stop that while loop i have to set Running to false which is done at another button `btnHalt`: ActionListener btnHalt_Click = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { textBox1.append("Poll loop stopped\r\n"); System.out.println("Hoper Stopped"); Running = false; } }; but `btnHalt` is not responding, whole frame is get freeze, also not showing any log in the `textarea`.
Please learn java naming conventions and stick to them.

以上就是JFrame freezes while running the code continuously的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准