mercredi 21 février 2018

Refreshing JFrame after invoking method through Reflections

I have buttons that add strings with method names to the commands ArrayList. When a certain other (play) button is pressed, I want all the commands to be run. My current problem is that after clicking the play button, you can only see the end state after all the commands have been run. I would like to see the intermediate states - the state of the JFrame after each individual command has been run. All the methods call frame.repaint() and frame.revalidate(). I tried adding Thread.sleep in the loop, but it did not work.

playButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
          try {
            for (String s : commands) {
              Method m = Robot.class.getMethod(s);
              m.invoke(null);
            }
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      });





Aucun commentaire:

Enregistrer un commentaire