protected void retrace(boolean check) { while (status == true) { for (counter = LOOPBACK; counter <= frameCW4.getWidth(); counter++ ) { for (counter = LOOPBACK; counter <= frameCW4.getHeight(); counter++) { { // System.out.println(counter); // xCoord = generator.nextInt(frameCW4.getWidth()); // yCoord = generator.nextInt(frameCW4.getHeight()); xCoord++; yCoord++; try { Thread.sleep(5); firstDrawPanel.repaint(); secondDrawPanel.repaint(); } catch (InterruptedException e) { e.printStackTrace(); } } } } for ( counter = frameCW4.getWidth(); counter >= LOOPBACK; counter--) { for (counter = frameCW4.getHeight(); counter >= LOOPBACK; counter --) { xCoord--; yCoord--; try { Thread.sleep(5); firstDrawPanel.repaint(); secondDrawPanel.repaint(); } catch (InterruptedException e) { e.printStackTrace(); } } } } }
This code makes the graphics object move through the JFrame, how do I do it such that, when a button is clicked, the graphics objects stop moving.