GT500FOMOCO
Programmer
I got my program to work, but it prints the image on it's side. I need to know which variables I've got in the wrong places. Here is my code, the problems (I think) are in
Building. Here is the code...
"and everything under the sun is in tune
but the sun is eclipsed by the moon." --Pink Floyd: Eclipse
"I'm going to spend eternity
reinstalling Windows." --Reinstalling Windows: by some British guy
Code:
class
Code:
import java.applet.Applet;
import java.awt.*;
import java.awt.geom.*;
import java.util.*;
public class Skyline extends Applet {
public void init() {
setBackground(Color.black);
}
public void paint(Graphics g) {
Graphics2D pen = (Graphics2D) g;
Stars starField = new Stars();
starField.drawStars(pen, getWidth(), getHeight());
Building structure = new Building();
structure.drawBuilding(pen);
}
class Stars {
public void drawStars(Graphics2D pen, int Width, int Height) {
Random generator = new Random();
int runs = 1;
while (runs <= 1000) {
int Xcord = generator.nextInt(Width - 3);
int Ycord = generator.nextInt(Height - 3);
Ellipse2D.Double star
= new Ellipse2D.Double(Xcord, Ycord, 3, 3);
pen.setColor(Color.white);
pen.fill(star);
runs++;
}
}
}
class Building {
public void drawBuilding(Graphics2D pen) {
Random generator = new Random();
int n = 1;
int n2 = 1;
int runs = 1;
String input = "";
String param = "";
while ((param = getParameter("building" + n)) != null) {
n++;
}
int height = getHeight();
int width = getWidth() / (n + 2);
int startX = width;
int startY = height;
while (runs <= n) {
int red = generator.nextInt(125) + 100,
green = generator.nextInt(125) + 100,
blue = generator.nextInt(125) + 100;
pen.setColor(new Color(red, green, blue));
height = getHeight();
input = getParameter("building" + n2);
height = Integer.parseInt(input);
height = startY - height;
Rectangle building = new Rectangle(startY, startX, height, width);
pen.fill(building);
startX = startX + width;
n2++;
runs++;
}
}
}
}
but the sun is eclipsed by the moon." --Pink Floyd: Eclipse
"I'm going to spend eternity
reinstalling Windows." --Reinstalling Windows: by some British guy