0% found this document useful (0 votes)
697 views

Cafewall Code

Uploaded by

api-242274655
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
697 views

Cafewall Code

Uploaded by

api-242274655
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

// // // // // //

Ishan Ranade 10/15/2013 CSE142 TA: Nadav Ashkenazi Assignment #3 This program will create a cafe wall

package Chapter3Exercises; import java.awt.*; public class CafeWall { //this variable determines the spacing between rows in a column public static final int SPACING = 2; //this is the main program that runs public static void main(String[] args) { DrawingPanel panel = new DrawingPanel(650, 400); Graphics g = panel.getGraphics(); panel.setBackground(Color.GRAY);; drawSingleRow(g, 0, 0, 20, 4); drawSingleRow(g, 50, 70, 30, 5); drawColumnOfRows(g, drawColumnOfRows(g, drawColumnOfRows(g, drawColumnOfRows(g, } //this method draw a single row with a specified number of public static void drawSingleRow(Graphics g, int x, int y, rs) { //this for loop determines how many pairs to draw for(int i = 1; i <= pairs; i++) { g.setColor(Color.BLACK); g.fillRect(x + 2 * (i - 1) * size, y, size, size); g.setColor(Color.BLUE); g.drawLine(x + 2 * (i - 1) * size, y, x + 2 * (i y + size); g.drawLine(x + 2 * (i - 1) * size + size, y, x + 2 y + size); g.setColor(Color.WHITE); g.fillRect(x + 2 * (i - 1) * size + size, y, size, } } pairs int size, int pai 10, 150, 25, 4, 0); 250, 200, 25, 3, 10); 425, 180, 20, 5, 10); 400, 20, 35, 2, 35);

1) * size + size, * (i - 1) * size, size);

//this method produces a columns of rows using the above method public static void drawColumnOfRows(Graphics g, int x, int y, int size, int pairs, int offset) { //this for loop determines how many rows to place in the column for(int i = 1; i <= pairs * 2; i++) { drawSingleRow(g, x + ( (i + 3) % 2) * offset, y + (i - 1) * size + ( i - 1) * SPACING, size, pairs); } } }

You might also like