My StarScape is still not running on its own after adding threading. I still have to click or resize to see the next frame of animation.
new StarScape:
// 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.*; import java.lang.*; public class StarScape extends JApplet implements Runnable { final int maxStars = 1000; String key = ""; String valid; int index; double myX; double myY; int myRadius; int myLayer; int rectX; int rectY; int rectXX; int rectYY; private long myStarDelay = 20; Star stars[] = new Star[maxStars+1];//make 1000 star objects public void init() { for (index = 0; index < maxStars; index++) { stars[index] = new Star();//fill array with stars }//end for }//end init public void start() { Thread t = new Thread(); t.start(); } public void run() { Graphics g = getGraphics(); do { paint(g); repaint(); }while (key == ""); } 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 valid = stars[index].starValid(); if (valid == "false") {//is star out of bounds? stars[index].resetStar(); } 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 }//end starscape// 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]; private double starX; private double starY; private int starLayer; public Star() { starX = Math.random() * 200 - 99;//star starts in a small square starY = Math.random() * 200 - 99;//in the center starLayer = (int)(Math.random() * 3);//random layer starAngle = (Math.sqrt((starX * starX)+(starY * starY)));//calculate the hypotenuse starField[0] = starX;//set data to star's arrary starField[1] = starY;//this is for current position starField[2] = starX / starAngle * starSpeed;//these set the next position starField[3] = starY / starAngle * starSpeed;//this is reltive current position starField[4] = starLayer;//back, mid, or foreground layer starField[5] = starRadius;//star starting size starField[6] = starSpeed * starLayer;//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() {//resetStar method starX = Math.random() * 200 - 99;//set new starting position starY = Math.random() * 200 - 99; starLayer = (int)(Math.random() * 3);//new random layer starAngle = (Math.sqrt((starX * starX)+(starY * starY)));//calculate new hypotenuse starField[0] = starX;//set data to star's array starField[1] = starY;//same as default constructor starField[2] = starX / starAngle * starSpeed; starField[3] = starY / starAngle * starSpeed; starField[4] = starLayer; starField[5] = starRadius; starField[6] = starSpeed * starLayer; starField[7] = starSteps; starField[8] = starAngle; }//end resetStar public String 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 return isValid; }//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 }//end class star