import java.awt.*; public class Box extends Rectangle { public Rectangle top, left, right_top, right_bottom; private double top_ratio = 0.4; private double bottom_ratio = 0.6; public Box(int x, int y, int w, int h) { super(x,y,w,h); setTop(); setLeft(); setRightTop(); setRightBottom(); } public void draw(Graphics g) { g.setColor(Color.cyan); g.fillRect(top.x, top.y, top.width, top.height); g.setColor(Color.yellow); g.fillRect(left.x, left.y, left.width, left.height); g.setColor(Color.blue); g.fillRect(right_top.x, right_top.y, right_top.width, right_top.height); g.setColor(Color.red); g.fillRect(right_bottom.x, right_bottom.y, right_bottom.width, right_bottom.height); } void setTop() { int _x, _y, _w, _h; _x = this.x; _y = this.y; _w = this.width; _h = (int)(this.height * top_ratio); top = new Rectangle(_x, _y, _w, _h); } void setLeft() { int _x, _y, _w, _h; _x = this.x; _y = top.y + top.height; _w = 4*top.width/5; _h = (int)(this.height * bottom_ratio); left = new Rectangle(_x, _y, _w, _h); } void setRightTop() { int _x, _y, _w, _h; _x = left.x + left.width; _y = left.y; _w = top.width/5; _h = left.height/2; right_top = new Rectangle(_x, _y, _w, _h); } void setRightBottom() { int _x, _y, _w, _h; _x = right_top.x; _y = right_top.y + right_top.height; _w = right_top.width; _h = left.height/2; right_bottom = new Rectangle(_x, _y, _w, _h); } }