Results 1 to 2 of 2
  1. #1
    ryuzog is offline Member
    Join Date
    Jan 2010
    Rep Power

    Default Animation doesn't show when used as action?

    I have this little input animation, basically just a pause between value changes, it shows nicely when I just place it in the main arguments.

    But when I try attaching it to a button, the program just freezes for the amount of time it takes to "input" and then it just shows the final product.

    Can I fix this? Do you guys need some example code?

    Java Code:
    	public void solve(){
    		for (int a = 0; a < 9; a++){
    			for (int b = 0; b < 9; b++){
    			    try {
    				} catch (InterruptedException e) {
    					// TODO Auto-generated catch block
    it just replaces button names, it works when I simply call the method, but when it's in:

    Java Code:
     final JMenuItem solve = new JMenuItem("Solve");
    	    solve.addActionListener(new ActionListener(){
    	    	public void actionPerformed(ActionEvent e){
    	    		JOptionPane.showMessageDialog(null, "WIN!!...wait...");
    When I have sleep set as 10, it waits a bit, then shows everything, set as 100, then waits 10 times as long.

    can anyone help?

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Rep Power


    Because code invoked from a "listener" executes on the GUI Event Dispatch Thread (EDT). Since you tell this thread to sleep the GUI can't repaint itself until all the code is finished executing. You need to start a separate Thread, so that thread sleeps and not the EDT.

    Read the section from the Swing tutorial on "Concurrency" for more information.

Similar Threads

  1. gui animation problems
    By helpisontheway in forum New To Java
    Replies: 2
    Last Post: 12-15-2009, 02:41 PM
  2. Fish animation
    By SwEeTAcTioN in forum AWT / Swing
    Replies: 3
    Last Post: 11-30-2009, 10:56 AM
  3. need help about animation ?
    By h9h in forum Java 2D
    Replies: 1
    Last Post: 10-30-2009, 11:41 AM
  4. GUI Animation
    By serfster in forum New To Java
    Replies: 2
    Last Post: 06-11-2008, 03:37 AM
  5. netbeans 6.0 not show commpunent or show blank page
    By fahimaamir in forum NetBeans
    Replies: 1
    Last Post: 01-26-2008, 06:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts