/* Project #7 Completing my class of bricks for polychroming pattern generation Lisa M. Snyder December 2, 1998 Illustrates creation of a graphic user defined class. Final project will incorporate class functions (methods), Mouse events, and loops. The point is to create a field of class objects (bricks) that can have their color modified to allow the user to play with polychrome patterns. A relatively complex function allows the bricks to be 'split' so that the bond pattern can be manipulated. A universal change allows the grout color to be changed for the entire pattern. */ import java.awt.*; import java.awt.event.*; public class brick{ private int xRef, yRef; private int b_width, b_height; private Color fillColor, groutColor; // ---------------------- Default Constructor ---------------------------- public brick() { xRef = 0; yRef = 0; b_width = 1; b_height = 1; fillColor = Color.red; groutColor = Color.black; } // ---------------------- Constructor ------------------------------------ public brick(int x, int y, int width, int height, Color fill) { xRef = x; yRef = y; b_width = width; b_height = height; fillColor = fill; groutColor = Color.black; //System.out.println ("base brick created" + xRef + " " + yRef); } // ---------------------- Copy Constructor ------------------------------ public brick(brick b) { b.xRef = xRef; b.yRef = yRef; b.b_width = b_width; b.b_height = b_height; b.fillColor = fillColor; b.groutColor = groutColor; } // ---------------------- Translate Brick ------------------------------ public void translate(int x, int y) { xRef = xRef+x; yRef = yRef+y; } // ---------------------- Destructor ?? ---------------------------------- // ---------------------- FUNCTIONS (METHODS) ---------------------------- // ---------------------- Set Brick Color -------------------------------- public void setColor(Color fill) { fillColor = fill; } // ---------------------- Repaint a Single Brick ------------------------- //public void single_paint() //{ // repaint(); // } // ---------------------- Bounding Box of a Single Brick ----------------- public Rectangle boundingBox() { return new Rectangle (xRef,yRef,b_width,b_height); } // ---------------------- Split Bricks ----------------------------------- public void split_brick() { b_width = b_width/2; } // ---------------------- Add Brick -------------------------------------- public brick add_brick() { System.out.println ("calling object=" + xRef + " " + yRef); brick brick_temp = new brick (xRef+b_width, yRef, b_width, b_height, fillColor); System.out.println ("brick_temp=" + brick_temp.xRef + " " + brick_temp.yRef); return brick_temp; } // -----------------------Paint for Class -------------------------------- public void paint(Graphics g) { g.setColor (fillColor); g.fillRect (xRef, yRef, b_width, b_height); g.setColor (groutColor); g.drawRect (xRef, yRef, b_width, b_height); } // ----------------------- Find if Inside ----------------------------------- public boolean inside(int x, int y) { if (x >= xRef && x <= xRef+b_width && y >= yRef && y <= yRef+b_height) return true; else return false; } // ---------------------- Universally Change Grout Color ----------------- public void changeGrout(Color new_grout) { groutColor = new_grout; } // ---------------------- Reset Brick Color ------------------------------ public void resetColor(Color reset_color) { fillColor = reset_color; } // -----------------------End of Class ----------------------------------- } /* // ---------------------- Split Bricks ----------------------------------- public void split_brick(brick b_array[],int picked) { b_width = b_width/2; //repaint(xRef,yRef,b_width*2,b_height); b_array[num+1] = new brick ((b_array[picked].xRef+b_array[picked].b_width),b_array[picked].yRef,b_array[picked].b_width,b_array[picked].b_height,b_array[picked].fillColor); //repaint(); } */