Ok so this is a personal project. I had made a QBasic program years ago and now i am translating it to be a java applet so I can show it off. I found a book on java programming and went through it completely before I started. I've got it down to just 7 errors.
Here is the code:
/* StarScape Applet By Jon Crawford first Java tranlastion */ import java.util.*; import java.util.Random; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class StarScape extends JApplet { public void paint(Graphics g){ int maxStars = 200, starSpeed = 2, starRadius = 1, speedA; int v, w, c, l; int stars[][] = new int[maxStars][7]; setBackground(Color.black); do { for(int ctrl = 0; ctrl < maxStars; ctrl++) { //if star is out of range, and all of them are at start, //erase last star position, and give star a new random start if( stars[ctrl][1] <= 1 || stars[ctrl][2] <= 1 || stars[ctrl][1] >= 799 || stars[ctrl][2] >= 599) { g.setColor(Color.black); g.drawOval(stars[ctrl][1], stars[ctrl][2], starRadius, starRadius); Random rand = new Random(); //start in small box in center v = rand.nextInt(200) - 99; w = rand.nextInt(200) - 99; if (v == 0) { v = 1; } if (w == 0) { w = 1; } //random color variable, specifies which of the three layers this star is in. //white = front, light grey = middle layer, dark grey = back layer c = rand.nextInt(3); stars[ctrl][7] = c; //adjust values to big box stars[ctrl][1] = v + 399; stars[ctrl][2] = w + 299; stars[ctrl][5] = starRadius; stars[ctrl][6] = rand.nextInt(10); //get angle //first error, these have been declared integers, yet compiler says "precision loss, these are doubles"? l = Math.sqrt((v * v)+(w * w)); //adjust speed acording to color/layer switch (stars[ctrl][7]) { case 3: speedA = starSpeed; break; case 2: speedA = starSpeed / 4; break; case 1: speedA = starSpeed / 2; break; default: speedA = starSpeed; }//end case //calculate new star position from old star position stars[ctrl][3] = v / l * speedA; stars[ctrl][4] = w / l * speedA; }//end if //erase old star g.setColor(Color.black); g.drawOval(stars[ctrl][1], stars[ctrl][2], starRadius, starRadius); //set old position to new position stars[ctrl][1] = stars[ctrl][1] + stars[ctrl][3]; stars[ctrl][2] = stars[ctrl][2] + stars[ctrl][4]; stars[ctrl][6] = stars[ctrl][6] + 1; //stars get faster as they get closer every 15 steps if (stars[ctrl][6] / 15 == (int)(stars[ctrl][6] / 15) && stars[ctrl][5] < 5) { stars[ctrl][5] = stars[ctrl][5] + 1; } //use color/layer number to set the color switch (stars[ctrl][7]) { case 1: g.setColor(Color.white); break; case 2: g.setColor(Color.lightGray); break; case 3: g.setColor(Color.darkGray); break; }//end case //draw new Star g.drawOval(stars[ctrl][1], stars[ctrl][2], starRadius, starRadius); }//end for //check for key press //this is not working either keyCode = kE.getKeyText(kE.getKeyCode()); }while (keyCode.equalsIgnoreCase ("")); //continue until a key is pressed }//end class }//end Starscape
I have also comment the sections where errors are found. Please help I am getting frustrated.
EDIT: one error fixed, code updated to reflect fix.