// CS 134 program to draw a warning sign // Third (& best) attempt - uses constants! import objectdraw.*; import java.awt.*; public class NoClicking3 extends WindowController { // specifications that control sign's shape // coordinates of sign's corner private static final int SIGN_LEFT = 200; private static final int SIGN_TOP = 70; // dimensions of sign private static final int SIGN_SIZE = 100; // space from circle to sign edge private static final int CIRCLE_INSET = 7; // Dimensions for "CLICKING" private static final int MESS_WIDTH = 40; private static final int MESS_HEIGHT = 10; // Dimensions for pole private static final int POLE_WIDTH = 5; private static final int POLE_HEIGHT = 150; // Coordinates and dimensions derived from specifications // Coordinates and dimensions of circle private static final int CIRCLE_LEFT = SIGN_LEFT + CIRCLE_INSET; private static final int CIRCLE_TOP = SIGN_TOP + CIRCLE_INSET; private static final int CIRCLE_SIZE = SIGN_SIZE - 2*CIRCLE_INSET; // Coordinates for "CLICKING" private static final int MESS_X = SIGN_LEFT + (SIGN_SIZE-MESS_WIDTH)/2; private static final int MESS_Y = SIGN_TOP + SIGN_SIZE/2 - MESS_HEIGHT/2; // inset to ends of diagonal private static final int LINE_INSET = SIGN_SIZE/2 - 5*(SIGN_SIZE/2 - CIRCLE_INSET)/7; // Coordinates for diagonal private static final int LINE_X1 = SIGN_LEFT + LINE_INSET; private static final int LINE_Y1 = SIGN_TOP + LINE_INSET; private static final int LINE_X2 = SIGN_LEFT + SIGN_SIZE - LINE_INSET; private static final int LINE_Y2 = SIGN_TOP + SIGN_SIZE - LINE_INSET; // Coordinates for the pole private static final int POLE_TOP = SIGN_TOP + SIGN_SIZE; private static final int POLE_LEFT = SIGN_LEFT + SIGN_SIZE/2 - POLE_WIDTH/2; public void begin() { // Instructions to construct the sign new FramedRect( SIGN_LEFT, SIGN_TOP, SIGN_SIZE, SIGN_SIZE, canvas); new FramedOval( CIRCLE_LEFT, CIRCLE_TOP, CIRCLE_SIZE, CIRCLE_SIZE, canvas); new Text( "CLICKING", MESS_X, MESS_Y, canvas); new Line(LINE_X1, LINE_Y1, LINE_X2, LINE_Y2, canvas); new FilledRect(POLE_LEFT, POLE_TOP, POLE_WIDTH, POLE_HEIGHT, canvas); } }