Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I did it! Now, why does it print on it's side?

Status
Not open for further replies.

GT500FOMOCO

Programmer
Jul 5, 2001
143
US
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
Code:
class
Building. Here is the code...

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 = &quot;&quot;;
            String param = &quot;&quot;;

            while ((param = getParameter(&quot;building&quot; + 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(&quot;building&quot; + n2);
                height = Integer.parseInt(input);

                height = startY - height;

                Rectangle building = new Rectangle(startY, startX, height, width);
                pen.fill(building);

                startX = startX + width;
                n2++;
                runs++;
            }
        }
    }
}
&quot;and everything under the sun is in tune
but the sun is eclipsed by the moon.&quot; --Pink Floyd: Eclipse


&quot;I'm going to spend eternity
reinstalling Windows.&quot; --Reinstalling Windows: by some British guy
 
That just caused it to not print anything. &quot;and everything under the sun is in tune
but the sun is eclipsed by the moon.&quot; --Pink Floyd: Eclipse


&quot;I'm going to spend eternity
reinstalling Windows.&quot; --Reinstalling Windows: by some British guy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top