Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 29

Thread: Challenge: I need an animation loop outside of the paint method.

  1. #1
    Member
    Join Date
    Aug 2011
    Posts
    86
    My Mood
    Lurking
    Thanks
    16
    Thanked 4 Times in 4 Posts

    Default Challenge: I need an animation loop outside of the paint method.

    I am confused as to this point. I just spent 4 hours last night trying to put the animation loop of my StarScape outside of the paint method so that my code does not cripple the system, and have hit a wall.

    I have tried to make a method called drawStar(Graphics g). when I call it like I call my other methods, i.e. stars[index].drawStar() It tells me that "drawStars(java.awt.Graphics) cannot be applied to ()"

    Could somebody give me and example code of how to accomplish this?

    To be helpful to me, here are some guide lines:

    1) Create a class Ball.java and an applet Dribble.java
    2) in the ball class describe methods for these behaviors:
    a) moveBall < this should change the x,y location data at least, for example, one pixel to the right. Does not matter, location data just needs to change.
    b) drawBall < this should include a paint method (if possible) and place a drawOval on the screen
    c) eraseBall < just what it says.

    3) since I'm using an array of objects in my project, the Dribble Applet should create at least 2 ball objects, but instead of ball1, ball2, use ball[num] where num is described in a for loop. This way the call to method would be ball[num].moveBall(). this already works well in my starscape to move the stars when I use: stars[index].moveStar().

    4) sucsessfully call the moveBall, drawBall and eraseBall, inside a do...while loop so that the balls keep moving. Again, this should be done outside a paint method, which is where I run into problems.

    Refer to http://www.javaprogrammingforums.com...-day-12-a.html. In that code, I call the moveStar method and some get methods to get the location data, this is done inside a do...while loop within my paint method which is a big no-no. I've tried to satisfy the above guidelines 1-4 in my starscape with no luck.

    Thank you for all your help.
    Last edited by Spidey1980; August 19th, 2011 at 09:36 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    put the animation loop of my StarScape outside of the paint method so that my code does not cripple the system
    To rewrite your StarScape program, take the do while loop out of the paint method. Just two lines with the do and the while, leave the contents of the loop.
    Create a thread and put the do while loop in its run method. Inside the loop do a sleep of a short duration and a call to repaint. Done.
    Also move the filling of the stars array outside of the paint method. Correct the constructor looking method to be a constructor and use it in the initialization loop.

  3. #3
    Member
    Join Date
    Aug 2011
    Posts
    86
    My Mood
    Lurking
    Thanks
    16
    Thanked 4 Times in 4 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    so in other words, the paint method should just loop through the total number of stars one time, moving each star one time. then in the do...while some where else a repaint() will call the paint method and move eachstar one time each time repaint is called?

    I was unsure of how repaint() works. Does it just make the program go through the paint(Graphics g) each time it is called?

    I have not learned threads yet, got some more reading to do. http://www.exampledepot.com/egs/java...sicThread.html

    I noticed that java does not like for and while loops in a class outside of a method.

    basically, can it look like this (do not try to run this, it is just a flow chart):

    public class starscape extends JApplet
    {
    create object array
    create thread object


    public void init()
    {

    for loop through objects
    {
    call constructor
    }//end for

    }//end init




    public void paint (Graphics g)
    {

    for loop through objects
    {
    call getX, getY, ect.
    g.fillOval(black)
    call moveStar, ect.
    call isValid, if not valid call resetStar
    call getX, getY, ect.
    g.fillOval(white)
    }//end for

    }//end paint


    public void makeHappen implements thread?
    {

    public void run()
    {

    do
    {
    repaint()
    }while

    }//end run
    }//end thread


    }//end class
    Last edited by Spidey1980; August 19th, 2011 at 10:46 AM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    how repaint() works. Does it just make the program go through the paint(Graphics g) each time it is called?
    Yes, in most cases.
    in a class outside of a method.
    Most executed statements should be in a method. Statements that Initialize variables can be outside.

  5. #5
    Member
    Join Date
    Aug 2011
    Posts
    86
    My Mood
    Lurking
    Thanks
    16
    Thanked 4 Times in 4 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    Quote Originally Posted by Norm View Post
    Statements that Initialize variables can be outside.
    unless they need a for loop.

    I'm not gonna Star1..Star2....Star1000. on 1000 different lines


    Can repaint be called outside of a thread, yet inside a method? (is using a thread absolutely necessary in this context? Regardless I need to learn threads anyways)
    Last edited by Spidey1980; August 19th, 2011 at 10:52 AM.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    Then you need to put the code in a method.

  7. #7
    Member
    Join Date
    Aug 2011
    Posts
    86
    My Mood
    Lurking
    Thanks
    16
    Thanked 4 Times in 4 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    Thank you. I will post back after some re-coding.

  8. #8
    Member
    Join Date
    Aug 2011
    Posts
    86
    My Mood
    Lurking
    Thanks
    16
    Thanked 4 Times in 4 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    okay it sort of works. I have to keep resizing the window to see the animation. Is there a way to make it run on it's own without the need to resize the window to see the next frame?

    here is the code:

    New StarScape.java:
    // starscape.java
    // by Jon Crawford
    import Star.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.geom.*;
    import java.io.*;
    import java.math.*;
     
    public class StarScape extends JApplet 
    {
      final int maxStars = 1000;
      String key = "";
      String valid;
      int index;
      double myX;
      double myY;
      int myRadius;
      double myLayer;
      int rectX;
      int rectY;
      int rectXX;
      int rectYY;
      Star stars[] = new Star[maxStars+1];//make 1000 star objects
     
      public void init()
      {
        for (index = 0; index < maxStars; index++)
        {
          myX = Math.random() * 200 - 99;//star starts in a small square
          myY = Math.random() * 200 - 99;//in the center
          myLayer = Math.random() * 3;//random layer
          stars[index] = new Star();//fill array with stars
        }//end for 
      }//end init
     
      public void paint(Graphics g)
      {
        g.setColor(Color.black);
        g.fillRect(0,0,800,600);// make the background black
        for (index = 0; index < maxStars; index++) 
        {
          stars[index].moveStar();//move the star
          stars[index].starValid();
          valid = stars[index].getValid();//is the star out of bounds?
          if (valid == "false")
          {//is star out of bounds?
            myX = Math.random() * 200 - 99;//set new starting position
            myY = Math.random() * 200 - 99;
            myLayer = Math.random() * 3;//new random layer
            stars[index].resetStar(myX, myY, myLayer);
          }  
          myX = stars[index].getStarX();
          myY = stars[index].getStarY();
          myRadius = stars[index].getStarRadius();//get data agian because star was moved
          myLayer = stars[index].getStarLayer();//layer just denotes shade of star. 
          if (myLayer == 3) 
          {
            g.setColor(Color.white);
          }else if (myLayer == 2) 
          {
            g.setColor(Color.lightGray);
          }else if (myLayer == 1) 
          {
            g.setColor(Color.darkGray);
          }else 
          {
            g.setColor(Color.white);//these set color based on layer
          }
          rectX = (int)(myX) - myRadius + 399;
          rectY = (int)(myY) - myRadius + 299;
          rectXX = myRadius * 2;
          rectYY = myRadius * 2;//set up the new star I mean rectangle
          g.fillOval(rectX, rectY, rectXX, rectYY);//draw star
        }//end for
      }//end paint
     
      public void doIt()
      {
        do
        {
          repaint();
        }while (key == "");
      }//end do it
    }//end starscape

    for the imported star.java please refer to: http://www.javaprogrammingforums.com...-day-12-a.html

  9. #9
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    unless they need a for loop.
    public class StaticInitializerInside
    {
      public final static String[] A_LOT_OF_STRINGS = new String[1000];
      static
      {
        int i = 0;
        for (String s : A_LOT_OF_STRINGS)
          A_LOT_OF_STRINGS[i++] = i + "!";
      }
    }

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

      stars[index] = new Star();//fill array with stars
    Why don't you use the "constructor" method to fill in the values when the Star object is created?

    Where is the Thread to run the loop creating the animation?
    Who calls the doIt method?
    Last edited by Norm; August 19th, 2011 at 11:21 AM.

  11. #11
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    You never call repaint() in your code. Repaint only 'requests' a paint, it doesn't force one. Resizing your window also requests a paint.

  12. #12
    Member
    Join Date
    Aug 2011
    Posts
    86
    My Mood
    Lurking
    Thanks
    16
    Thanked 4 Times in 4 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    I thought
    stars[index] = new Star();//fill array with stars
    was calling the consrtuctor

  13. #13
    Member
    Join Date
    Aug 2011
    Posts
    86
    My Mood
    Lurking
    Thanks
    16
    Thanked 4 Times in 4 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    how do I force a repaint?

  14. #14
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    Quote Originally Posted by Spidey1980 View Post
    how do I force a repaint?
    Sean4u just told you.

    Recommended reading: Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  15. #15
    Member
    Join Date
    Aug 2011
    Posts
    86
    My Mood
    Lurking
    Thanks
    16
    Thanked 4 Times in 4 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    Quote Originally Posted by Norm View Post
      stars[index] = new Star();//fill array with stars
    Why don't you use the "constructor" method to fill in the values when the Star object is created?

    Where is the Thread to run the loop creating the animation?
    Who calls the doIt method?

    Thought that was calling the constructor

    I still have more reading to do on threads, I gotta go to work soon so I'm leaving that till tonight

    lol doIt should be converted to a thread i guess.

    It looks like it should work almost as is since when resizing the window the stars do move, I just need to force a repaint somehow.

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    Where is the code for the Star class's constructor?
    There is a method in the class that looks like a constructor. Why not convert that to be a constructor and use it?
    Make the variables that belong to the Star class private to that class vs having them global.
    In your initialization loop you give values to 3 variables but those values are never used:
          myX = Math.random() * 200 - 99;//star starts in a small square
          myY = Math.random() * 200 - 99;//in the center
          myLayer = Math.random() * 3;//random layer
          stars[index] = new Star();//fill array with stars

    Those variables should be passed to the Star class constructor.

  17. #17
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    how do I force a repaint?
    By doing what you were doing the other day that crippled my PC. You really don't want to force a repaint. What you want to do is to time your requests to repaint at a nice rate that the windowing system can comply with. Anything else will work really, really badly. Norm is telling you all the right things, you just need to spend a bit more time re-reading and polishing up your code. You only really need a thread for this if you're going to be doing something else as well as animating the stars. If you're only going to be animating stars, you can just sleep the *current thread* - that's a clue as to which method in Thread you need to get access to it.

  18. #18
    Member
    Join Date
    Aug 2011
    Posts
    86
    My Mood
    Lurking
    Thanks
    16
    Thanked 4 Times in 4 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    Quote Originally Posted by Norm View Post
    Where is the code for the Star class's constructor?
    There is a method in the class that looks like a constructor. Why not convert that to be a constructor and use it?
    Make the variables that belong to the Star class private to that class vs having them global.
    In your initialization loop you give values to 3 variables but those values are never used:
          myX = Math.random() * 200 - 99;//star starts in a small square
          myY = Math.random() * 200 - 99;//in the center
          myLayer = Math.random() * 3;//random layer
          stars[index] = new Star();//fill array with stars

    Those variables should be passed to the Star class constructor.
    They are being passed, your only seeing half the code here. It does work I assure you, I just want to make it so it is not system crippling.

    The constructor:
    public void Star(double myX, double myY, double myLayer)
      {
        starAngle = (Math.sqrt((myX * myX)+(myY * myY)));//calculate the hypotenuse
        starField[0] = myX;//set data to star's arrary
        starField[1] = myY;//this is for current position
        starField[2] = myX / starAngle * starSpeed;//these set the next position
        starField[3] = myY / starAngle * starSpeed;//this is reltive current position
        starField[4] = myLayer;//back, mid, or foreground layer
        starField[5] = starRadius;//star starting size
        starField[6] = starSpeed * myLayer;//the starting speed
        starField[7] = starSteps;//star has taken 0 steps, every 5 steps star grows and speeds up
        starField[8] = starAngle;//store the hypotenuse
      }//end constructor

    for Star.java please see: http://www.javaprogrammingforums.com...-day-12-a.html


    Quote Originally Posted by Sean4u View Post
    What you want to do is to time your requests to repaint at a nice rate that the windowing system can comply with.
    do you mind spoonfeeding me the one liner that will acomplish that? Else I will attemp figure it out after work.
    Last edited by Spidey1980; August 19th, 2011 at 11:43 AM.

  19. #19
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    If it was a constructor it would say
    public Star(/*whatever*/)
    What you've posted there is a method called Star with a void return type.

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    public void Star(double myX, double myY, double myLayer)
    That is not a constructor. Constructors do NOT have a void. This is the line of code I have mentioned in posts 2, 10 and 16.

    Also look at this line, it doesn't pass any arguments:
     stars[index] = new Star();//fill array with stars

  21. #21
    Member
    Join Date
    Aug 2011
    Posts
    86
    My Mood
    Lurking
    Thanks
    16
    Thanked 4 Times in 4 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    Quote Originally Posted by Sean4u View Post
    What you've posted there is a method called Star with a void return type.
    lol and yet it works. I did not want to become a hacker....

    and when I remove the void it tells me I forget to add a return.

    Is this because I forgot to put in a default constructor, and I just have the overloaded one?

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    when I remove the void it tells me I forget to add a return.
    When you get errors that you don't understand, you need to post them instead of ignoring them.

  23. #23
    Member
    Join Date
    Aug 2011
    Posts
    86
    My Mood
    Lurking
    Thanks
    16
    Thanked 4 Times in 4 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    That's better... I had forgot java wants two constructors:

    public Star()
      {
        for (int num = 0;num < 9; num++)
        {
          starField[num] = 0;
        }// end for
      }//end default consructor
     
      public Star(double myX, double myY, double myLayer)
      {
        starAngle = (Math.sqrt((myX * myX)+(myY * myY)));//calculate the hypotenuse
        starField[0] = myX;//set data to star's arrary
        starField[1] = myY;//this is for current position
        starField[2] = myX / starAngle * starSpeed;//these set the next position
        starField[3] = myY / starAngle * starSpeed;//this is reltive current position
        starField[4] = myLayer;//back, mid, or foreground layer
        starField[5] = starRadius;//star starting size
        starField[6] = starSpeed * myLayer;//the starting speed
        starField[7] = starSteps;//star has taken 0 steps, every 5 steps star grows and speeds up
        starField[8] = starAngle;//store the hypotenuse
      }//end  overloaded constructor

    But I still want to force a repaint.
    Last edited by Spidey1980; August 19th, 2011 at 11:59 AM. Reason: double post

  24. #24
    Member
    Join Date
    Aug 2011
    Posts
    86
    My Mood
    Lurking
    Thanks
    16
    Thanked 4 Times in 4 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    complete code so far:

    StarScape.java
    // starscape.java
    // by Jon Crawford
    import Star.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.geom.*;
    import java.io.*;
    import java.math.*;
     
    public class StarScape extends JApplet 
    {
      final int maxStars = 1000;
      String key = "";
      String valid;
      int index;
      double myX;
      double myY;
      int myRadius;
      double myLayer;
      int rectX;
      int rectY;
      int rectXX;
      int rectYY;
      Star stars[] = new Star[maxStars+1];//make 1000 star objects
     
      public void init()
      {
        for (index = 0; index < maxStars; index++)
        {
          myX = Math.random() * 200 - 99;//star starts in a small square
          myY = Math.random() * 200 - 99;//in the center
          myLayer = Math.random() * 3;//random layer
          stars[index] = new Star();//fill array with stars
        }//end for 
      }//end init
     
      public void paint(Graphics g)
      {
        g.setColor(Color.black);
        g.fillRect(0,0,800,600);// make the background black
        for (index = 0; index < maxStars; index++) 
        {
          stars[index].moveStar();//move the star
          stars[index].starValid();
          valid = stars[index].getValid();//is the star out of bounds?
          if (valid == "false")
          {//is star out of bounds?
            myX = Math.random() * 200 - 99;//set new starting position
            myY = Math.random() * 200 - 99;
            myLayer = Math.random() * 3;//new random layer
            stars[index].resetStar(myX, myY, myLayer);
          }  
          myX = stars[index].getStarX();
          myY = stars[index].getStarY();
          myRadius = stars[index].getStarRadius();//get data agian because star was moved
          myLayer = stars[index].getStarLayer();//layer just denotes shade of star. 
          if (myLayer == 3) 
          {
            g.setColor(Color.white);
          }else if (myLayer == 2) 
          {
            g.setColor(Color.lightGray);
          }else if (myLayer == 1) 
          {
            g.setColor(Color.darkGray);
          }else 
          {
            g.setColor(Color.white);//these set color based on layer
          }
          rectX = (int)(myX) - myRadius + 399;
          rectY = (int)(myY) - myRadius + 299;
          rectXX = myRadius * 2;
          rectYY = myRadius * 2;//set up the new star I mean rectangle
          g.fillOval(rectX, rectY, rectXX, rectYY);//draw star
        }//end for
      }//end paint
     
      public void doIt()
      {
        do
        {
          repaint();
        }while (key == "");
      }//end do it
    }//end starscape

    Star.java
    // star.java
    // by Jon Crawford
    package Star;
     
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.geom.*;
    import java.io.*;
    import java.math.*;
     
    public class Star {
     
      private final int starSpeed = 1;
      private final int starRadius = 1;
      private final int starSteps = 0;
      private final float[] invalidValues = new float[]{ -399f, -299f, 399f, 299f, 0f, 0f};
      private String isValid = "false";
      private double starAngle;
      private double starField[] = new double[9];
     
      public Star()
      {
        for (int num = 0;num < 9; num++)
        {
          starField[num] = 0;
        }// end for
      }//end consructor
     
      public Star(double myX, double myY, double myLayer)
      {
        starAngle = (Math.sqrt((myX * myX)+(myY * myY)));//calculate the hypotenuse
        starField[0] = myX;//set data to star's arrary
        starField[1] = myY;//this is for current position
        starField[2] = myX / starAngle * starSpeed;//these set the next position
        starField[3] = myY / starAngle * starSpeed;//this is reltive current position
        starField[4] = myLayer;//back, mid, or foreground layer
        starField[5] = starRadius;//star starting size
        starField[6] = starSpeed * myLayer;//the starting speed
        starField[7] = starSteps;//star has taken 0 steps, every 5 steps star grows and speeds up
        starField[8] = starAngle;//store the hypotenuse
      }//end constructor
     
      public void moveStar() 
      {//mutator method
        System.out.println("") ;    
        starField[0] = starField[0] + starField[2];//next position becomes the curent position 
        starField[1] = starField[1] + starField[3];       
        starField[2] = starField[0] / starField[8] * starField[6];//new next position
        starField[3] = starField[1] / starField[8] * starField[6];
        starField[7] = starField[7] + 1;//increment steps
        if (starField[7] / 5 == (int)(starField[7] / 5) && starField[5] < 20)
        {//if star has taken 5 steps
          starField[5] = starField[5] + 1;//increment size
          starField[6] = starField[6] + 1;//increment speed
        }//end if      
      }//end moveStar
     
      public void resetStar(double myX, double myY, double myLayer)
      {//resetStar method
        starAngle = (Math.sqrt((myX * myX)+(myY * myY)));//calculate new hypotenuse
        starField[0] = myX;//set data to star's array
        starField[1] = myY;//same as default constructor
        starField[2] = myX / starAngle * starSpeed;
        starField[3] = myY / starAngle * starSpeed;
        starField[4] = myLayer;
        starField[5] = starRadius;
        starField[6] = starSpeed * myLayer;
        starField[7] = starSteps;
        starField[8] = starAngle;
      }//end resetStar
     
      public void starValid()
      {//isValid method
        if(starField[0] > invalidValues[0] && starField[1] > invalidValues[1] && starField[0] < 
     
    invalidValues[2] && starField[1] < invalidValues[3])
        {//in bounds?
          isValid = "true";
        }else
        {//out of bounds
          isValid = "false";
        }//end if
      }//end is valid
     
      public int getStarX() 
      {//get method
        return (int)(Math.round(starField[0]));
      }//end getStarX
     
      public int getStarY() 
      {//get method
        return (int)(Math.round(starField[1]));
      }//end getStarY
     
      public int getStarRadius() 
      {//get method
        return (int)(Math.round(starField[5]));
      }//end getStarRadius
     
      public int getStarLayer() 
      {//get method
        return (int)(Math.round(starField[4]));
      }//end getStarLayer
      public String getValid()
      {//get method
        return isValid;
      }//end isValid
     
    }//end class star

    later I'll work on threads, I hate that right now I have to resize the window constantly to see the animation

  25. #25
    Member
    Join Date
    Aug 2011
    Posts
    86
    My Mood
    Lurking
    Thanks
    16
    Thanked 4 Times in 4 Posts

    Default Re: Challenge: I need an animation loop outside of the paint method.

    validate(); has the same result as repaint();

Page 1 of 2 12 LastLast

Similar Threads

  1. Inheriting Applet and paint() GUI Method Logic?
    By Jakesta42 in forum Object Oriented Programming
    Replies: 1
    Last Post: August 8th, 2011, 06:58 AM
  2. [SOLVED] How do you get this fountain to animate with paint method?
    By javapenguin in forum What's Wrong With My Code?
    Replies: 48
    Last Post: May 31st, 2011, 04:00 PM
  3. Blender file with animation, how to import OBJ(w/ animation) into Java?
    By cr80expert5 in forum Object Oriented Programming
    Replies: 0
    Last Post: May 12th, 2011, 03:11 AM
  4. Paint program adding classes to main method class
    By Maxfmc in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 15th, 2011, 07:01 PM
  5. Replies: 3
    Last Post: April 18th, 2010, 10:08 AM