Results 1 to 3 of 3

Thread: JPanel motion

  1. #1
    batyuska87 is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default JPanel motion

    Hi!

    I'm working on a simple aplication where is an JFrame, and 2 JPanels on it.
    I would like to write an simple motion with these JPanels. I implemented a simple version, but there is some flickering on the screen. How could I solve it?
    Here is my code:

    Jpanel c3 = new JPanel();
    Graphics g = this.getGraphics();
    c3.setLocation(30, 30);
    for(int i=0;i<100;i++)
    {
    c3.setLocation(130 + i, 30);
    this.update(g); //this is currently the JFrame.update
    try
    {
    Thread.sleep(10);
    }
    catch(InterruptedException e)
    {
    e.printStackTrace();
    }
    }

    Please help me...

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You seem to be doing graphics wrong including calling getGraphics on a component. I suggest that you read the Graphics tutorials and see how to do graphics correctly and your problems will correct themselves. If you want to move a component, then use a null layout, a Swing Timer and change it's location in the Timer. Again the tutorials will help.

  3. #3
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,839
    Rep Power
    8

    Default

    Ugh, crossposted: JPanel motion
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. JPanel motion
    By batyuska87 in forum AWT / Swing
    Replies: 0
    Last Post: 03-06-2011, 09:17 AM
  2. Moving Objects in an circlelair motion.
    By Thomask in forum Java Applets
    Replies: 8
    Last Post: 02-17-2011, 05:23 PM
  3. help on motion detection
    By MarkWilson in forum Advanced Java
    Replies: 4
    Last Post: 12-07-2009, 06:45 AM
  4. Choppy motion / graphics
    By Atriamax in forum Java Applets
    Replies: 5
    Last Post: 09-17-2009, 06:06 AM
  5. Simulating Brownian Motion
    By ixhabbaba in forum Java Applets
    Replies: 2
    Last Post: 11-11-2007, 08:53 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
  •