Results 1 to 1 of 1
  1. #1
    blue50 is offline Member
    Join Date
    Nov 2010
    Rep Power

    Default How to pass variable back from thread for animation

    Hello how do I pass a variable (ScrollX) back from a thread to animate a ball bouncing around on a Jpanel... The following code has everything working except I cannot figure out how to pass the position variable back to paintcomponent so when i repaint it does not move...

    Also the only way I could get the paintcomponent to work on the jpanel was to call it from the jpanel constructor is there some other way to do this more efficiently?

    Thanks for the Help
    Java Code:
    import java.awt.*;
    import javax.swing.*;	
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent; 
    class UserInterfaceSetup
    {	 int ScrollX;
    	 JFrame frame = new JFrame("UserInterface");	
             JPanel Panel1 = new JPanel(){  
                                                      public void paintComponent(Graphics g) 
    	public void ui() 		
    		UpdatePlot UpdatePlot1 = new UpdatePlot();
    		new Thread(UpdatePlot1).start();	
    class UpdatePlot extends JPanel implements Runnable  
    		public UpdatePlot(){}	
    		public void run()  
    			 ScrollX = (int) (Math.random() * 300);
        		try {  
            	    } catch (Exception ex) {}
    public class UserInterface extends UserInterfaceSetup
    	public static void main(String[] args)
    		UserInterfaceSetup n = new UserInterfaceSetup();
    Thanks again for the help!
    Last edited by blue50; 12-02-2010 at 06:03 AM. Reason: left something out...and comments messed up the tabs

Similar Threads

  1. pass a variable from one object to another
    By kev670 in forum New To Java
    Replies: 3
    Last Post: 11-25-2010, 02:20 AM
  2. Replies: 2
    Last Post: 04-18-2010, 05:48 AM
  3. Jframe pass variable to Applet
    By wayn in forum AWT / Swing
    Replies: 0
    Last Post: 03-10-2010, 10:54 AM
  4. How to pass a variable to another frame.
    By DJCali in forum New To Java
    Replies: 10
    Last Post: 10-14-2009, 04:57 AM
  5. How pass variable from jsp to servelet
    By shiva in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 04-22-2009, 02:55 PM

Posting Permissions

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