/** [Internal] */ public void paintComponent(Graphics g) { boolean opq = true; if (theOpaque != null) opq = theOpaque; super.setOpaque(opq); // if(theBackground!=null)super.setBackground(theBackground); super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; Rectangle rt = getBounds(); rt.x = 0; rt.y = 0; doBuffer(g2, opq, rt); chkFPS(); }
private static boolean testRectangleArch() { boolean pass = true; int test = 1; int cnt; Rectangle rect; Class cl; Class[] temp; System.out.println("Rectangle architecture tests..."); rect = new Rectangle(4.3, 5.6, new Point(-99, 66), Color.cyan, false); cl = rect.getClass(); pass &= test(cl.getConstructors().length == 1, test++); pass &= test((temp = cl.getInterfaces()).length == 1, test++); pass &= test(temp[0].getName().equals("Shape"), test++); pass &= test(verifyEqualsMethodSignature(cl), test++); cnt = countModifiers(cl.getDeclaredMethods(), Modifier.PUBLIC); pass &= test(cnt == 12, test++); cnt = cl.getFields().length; pass &= test(cnt == 0, test++); cnt = countModifiers(cl.getDeclaredFields(), Modifier.PROTECTED); pass &= test(cnt == 0, test++); cnt = countModifiers(cl.getDeclaredFields(), Modifier.PRIVATE); pass &= test(cnt == 5, test++); // Count and test number of of PACKAGE fields cnt = cl.getDeclaredFields().length - countModifiers(cl.getDeclaredFields(), Modifier.PRIVATE) - countModifiers(cl.getDeclaredFields(), Modifier.PROTECTED) - countModifiers(cl.getDeclaredFields(), Modifier.PUBLIC); pass &= test(cnt == 0, test++); return pass; }
private static boolean testRectangle() { boolean pass = true; int test = 1; Rectangle rect; System.out.println("Rectangle tests..."); rect = new Rectangle(4.3, 5.6, new Point(-99, 66), Color.cyan, false); pass &= test(approx(rect.getArea(), 4.3 * 5.6, 0.000001), test++); pass &= test(rect.getColor().equals(Color.cyan), test++); rect.setColor(Color.black); pass &= test(rect.getColor().equals(Color.black), test++); pass &= test(!rect.getFilled(), test++); rect.setFilled(true); pass &= test(rect.getFilled(), test++); pass &= test(rect.getWidth() == 4.3, test++); pass &= test(rect.getHeight() == 5.6, test++); rect.setWidth(4.321); pass &= test(rect.getWidth() == 4.321, test++); rect.setHeight(89.21); pass &= test(rect.getHeight() == 89.21, test++); pass &= test(approx(rect.getArea(), 4.321 * 89.21, 0.000001), test++); pass &= test(rect.getPosition().equals(new Point(-99, 66)), test++); rect.move(new Point(-5, -7)); pass &= test(rect.getPosition().equals(new Point(-104, 59)), test++); Rectangle rect2 = new Rectangle(4.321, 89.21, new Point(-104, 59), Color.black, true); pass &= test(rect.equals(rect2), test++); Rectangle rect3 = new Rectangle(4.3219, 89.21, new Point(-104, 59), Color.black, false); pass &= test(!rect2.equals(rect3), test++); rect3 = new Rectangle(4.321, 89.219, new Point(-104, 59), Color.black, false); pass &= test(!rect2.equals(rect3), test++); rect3 = new Rectangle(4.321, 89.21, new Point(-104, 59), Color.red, false); pass &= test(!rect2.equals(rect3), test++); rect3 = new Rectangle(4.321, 89.21, new Point(104, 59), Color.black, false); pass &= test(!rect2.equals(rect3), test++); pass &= test(!rect2.equals(null), test++); pass &= test(!rect2.equals(new String("Whatever")), test++); return pass; }
// Graphics2D g=getG();return g==null?null:g.getClipBounds();} public Rectangle getClipBounds(Rectangle r) { Shape s = bufferClip(); if (s == null) return null; r.setBounds(bufferClip().getBounds()); return r; }