1

Please someone give me an example for create a GUI which contain a grid of squares (or buttons) using java acm packages.

Guest
  • 53
  • 2
  • 15

2 Answers2

0

you can use square boxes to create a grid

GRect []grect = new GRect[rows][colums];

for(int i=0; i<rows; i++){
    for (int j=0; j<colums; j++){
        grect[i][j] = new GRect(x, y, width, height);    //here x and y are the x,y coordinates of the box
                                                         // widht and height are the width and height of the box  
        add(grect[i][j]); 
    }

}

for more details follow this link

tharinduNA
  • 580
  • 5
  • 12
0

i don't think that it is posible to add squares using GRect to JFrame,anyway can do it in this way. First you have to extend you class to GraphicsProgram, something like this

public class your_class extends GraphicsProgram{

  //here you can create the grid as I mentioned above

}

tharinduNA
  • 580
  • 5
  • 12