I had to make an applet of a Skyline using 3 classes (A Skyline Class, a Building Class, and a Skyline Panel class). I finished that part (I made my Skyline), but now I need to add yellow windows to the buildings (say...3-5 windows per building), and I'm not sure how to do that. Will someone please help me.
The assignment says (in reference to the Building class), "draw() is where the windows are drawn at an x,y location within the dimensions of the building. You choose the size of the windows and how many.
This class contains a constructor, Building(int upperX, int upperY, int nHeight, int nWidth), that initializes the current building's x/y location and height and width using the parameters. It also initializes the number of windows the building contains."
I don't understand the part about the windows. I was able to construct the buildings though. Here's part of my code.
This thread is effectively a dupe and hereby closed. Please keep everything in the other thread.
-ViRGE
The assignment says (in reference to the Building class), "draw() is where the windows are drawn at an x,y location within the dimensions of the building. You choose the size of the windows and how many.
This class contains a constructor, Building(int upperX, int upperY, int nHeight, int nWidth), that initializes the current building's x/y location and height and width using the parameters. It also initializes the number of windows the building contains."
I don't understand the part about the windows. I was able to construct the buildings though. Here's part of my code.
Code:
import java.awt.*;
public class Building
{
private int x, y, width, height;
private Color color;
private String string;
//-----------------------------------------------------------------
// Constructor: Sets up this building with the specified values.
//-----------------------------------------------------------------
public Building (Color shade, int upperX, int upperY, int nWidth, int nHeight) {
color = shade;
x = upperX;
y = upperY;
width = nWidth;
height = nHeight;
}
//-----------------------------------------------------------------
// Draws this building in the specified graphics context.
//-----------------------------------------------------------------
public void draw (Graphics page)
{
page.setColor (color);
page.fillRect (x, y, width, height);
}
//-----------------------------------------------------------------
// Color mutator.
//-----------------------------------------------------------------
public void setColor (Color shade)
{
color = shade;
}
//-----------------------------------------------------------------
// X mutator.
//-----------------------------------------------------------------
public void setX (int upperX)
{
x = upperX;
}
//-----------------------------------------------------------------
// Y mutator.
//-----------------------------------------------------------------
public void setY (int upperY)
{
y = upperY;
}
//-----------------------------------------------------------------
// width mutator.
//-----------------------------------------------------------------
public void setWidth (int nWidth)
{
width = nWidth;
}
//-----------------------------------------------------------------
// height mutator.
//-----------------------------------------------------------------
public void setheight (int nHeight)
{
height = nHeight;
}
//-----------------------------------------------------------------
// width accessor.
//-----------------------------------------------------------------
public int getWidth ()
{
return width;
}
//-----------------------------------------------------------------
// height accessor.
//-----------------------------------------------------------------
public int getHeight ()
{
return height;
}
//-----------------------------------------------------------------
// Color accessor.
//-----------------------------------------------------------------
public Color getColor ()
{
return color;
}
//-----------------------------------------------------------------
// X accessor.
//-----------------------------------------------------------------
public int getX ()
{
return x;
}
//-----------------------------------------------------------------
// Y accessor.
//-----------------------------------------------------------------
public int getY ()
{
return y;
}
}
import javax.swing.*;
import java.awt.*;
public class SkylinePanel extends JPanel
{
private Building building1, building2, building3, building4, building5;
private Window window1;
//-----------------------------------------------------------------
// Constructor: Creates five Building objects.
//-----------------------------------------------------------------
public SkylinePanel()
{
building1 = new Building (Color.black, 100, 380, 40, 100);
building2 = new Building (Color.black, 170, 290, 80, 190);
building3 = new Building (Color.black, 285, 80, 100, 400);
building4 = new Building (Color.black, 450, 270, 80, 210);
building5 = new Building (Color.black, 580, 360, 45, 120);
setPreferredSize(new Dimension(640, 480));
setBackground (Color.cyan);
}
//-----------------------------------------------------------------
// Draws this panel by requesting that each building draw itself.
//-----------------------------------------------------------------
public void paintComponent (Graphics page)
{
super.paintComponent(page);
building1.draw(page);
building2.draw(page);
building3.draw(page);
building4.draw(page);
building5.draw(page);
}
}
This thread is effectively a dupe and hereby closed. Please keep everything in the other thread.
-ViRGE
Last edited by a moderator: