Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

In need of help with making 4x4 grid

 
kenny gill
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This is a 2 part project that involves me first making a rectangle and then using it to make a 4x4 grid to display different types of color. The problem is that I have never made or been shown how to make a grid.

here is the project to help clarify:

"Box.java should have these instance variables (all of type int): upperLeftX, upperLeftY, height, width, and one more instance variable of type Color named boxColor. Make them all private and provide Getters and Setters for each instance variable. Tip: Eclipse will build getters and setters for you. Go to the Menu bar in Eclipse and select Source -> Generate Getters and Setters.

Provide the body of the following Constructor that sets the values of the instance variables:

public Box(int upperX, int upperY, int h, int w, Color myColor)

Create a method called display(Graphics g) that uses setColor(boxColor); and fillRect(upperLeftX,upplerLeftY,width, height); to fill our box.

PART II
Also in the java1_BoxProject, Make a Java applet named Grid.java. This applet should display a 4 x 4 grid of boxes, each with a different color (there are 13 standard colors you can look up in the Color Class in the API, you can use a few twice to get 16 boxes).

You must create 16 instances of the Box class and display them. Do not reuse just one box object".

here is my code so far:




 
Campbell Ritchie
Sheriff
Posts: 48917
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what is the question?
 
kenny gill
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

To show an example of a 4x4 grid
 
B Alin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here you go :


and



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic