/** getReady: Initialize the game */ private void getReady() { // Make up the bricks double brickPerWidth = (getWidth() - DIST_BRICK_WALL * 2 - DIST_BRICK_BRICK * (NUM_BRICK_ROW - 1)) / NUM_BRICK_ROW; double brickPerHeight = BRICK_HEIGHT; double x_start = DIST_BRICK_WALL; double y_start; for (int i = 1; i <= NUM_BRICK_ROW; i++) { for (int j = 1; j <= NUM_BRICK_COL; j++) { y_start = 50 + (j - 1) * (DIST_BRICK_BRICK + brickPerHeight); GRect tmpbrick = new GRect(brickPerWidth, brickPerHeight); tmpbrick.setFilled(true); add(tmpbrick, x_start, y_start); } x_start += DIST_BRICK_BRICK + brickPerWidth; } // Make up the board board = new GRect(BOARD_WIDTH, BOARD_HEIGHT); board.setFilled(true); add(board, (getWidth() - BOARD_WIDTH) / 2, (getHeight() - 30)); // Place the ball ball = new GOval(BALL_RADIUS * 2, BALL_RADIUS * 2); ball.setFilled(true); ball.setColor(Color.RED); add(ball, (getWidth() - BALL_RADIUS * 2) / 2, (getHeight() - 30 - BALL_RADIUS * 2)); // Set up random generator rgen = RandomGenerator.getInstance(); // Add Listeners addMouseListeners(); }
public void run() { GOval o = new GOval(40, 40); o.setColor(Color.RED); o.setFilled(true); add(o, 100, 100); while (true) { pause(WAIT); o.move(xMove, yMove); } }
/* Draw graph line with the name and rating */ private void drawEntry(NameSurferEntry entry, int entryNumber) { /* Draws graph line */ for (int i = 0; i < NDECADES - 1; i++) { int position1 = entry.getRank(i); int position2 = entry.getRank(i + 1); double x1 = i * (getWidth() / NDECADES); double x2 = (i + 1) * (getWidth() / NDECADES); double y1 = 0; double y2 = 0; if (position1 != 0 && position2 != 0) { y1 = GRAPH_MARGIN_SIZE + (getHeight() - GRAPH_MARGIN_SIZE * 2) * position1 / MAX_RANK; y2 = GRAPH_MARGIN_SIZE + (getHeight() - GRAPH_MARGIN_SIZE * 2) * position2 / MAX_RANK; } else if (position1 == 0 && position2 == 0) { y1 = getHeight() - GRAPH_MARGIN_SIZE; y2 = y1; } else if (position1 == 0) { y1 = getHeight() - GRAPH_MARGIN_SIZE; y2 = GRAPH_MARGIN_SIZE + (getHeight() - GRAPH_MARGIN_SIZE * 2) * position2 / MAX_RANK; } else { y1 = GRAPH_MARGIN_SIZE + (getHeight() - GRAPH_MARGIN_SIZE * 2) * position1 / MAX_RANK; y2 = getHeight() - GRAPH_MARGIN_SIZE; } GLine line = new GLine(x1, y1, x2, y2); /* Set line color */ if (entryNumber % 4 == 0) { line.setColor(Color.BLUE); } else if (entryNumber % 4 == 1) { line.setColor(Color.RED); } else if (entryNumber % 4 == 2) { line.setColor(Color.MAGENTA); } else if (entryNumber % 4 == 3) { line.setColor(Color.BLACK); } add(line); } /* Add label with the name and ranking */ for (int i = 0; i < NDECADES; i++) { String name = entry.getName(); int position = entry.getRank(i); String positionString = Integer.toString(position); String label = name + " " + positionString; double x = i * (getWidth() / NDECADES) + 10; double x1 = x - NDECADES; double y; int R = 5; if (position != 0) { y = GRAPH_MARGIN_SIZE + (getHeight() - GRAPH_MARGIN_SIZE * 2) * position / MAX_RANK; } else { /* Add "*" if name was not used and remove marker point */ label = name + " *"; y = getHeight() - GRAPH_MARGIN_SIZE - 10; R = 0; } /* Add marker point */ GOval marker = new GOval(x1, y - 2, R, R); /* Got "y-2" by scientific research =) */ marker.setFilled(true); GLabel nameLabel = new GLabel(label, x, y); nameLabel.setFont(new Font("Times Roman", Font.BOLD, 12)); /* Set label color */ if (entryNumber % 4 == 0) { nameLabel.setColor(Color.BLUE); marker.setColor(Color.BLUE); } else if (entryNumber % 4 == 1) { nameLabel.setColor(Color.RED); marker.setColor(Color.RED); } else if (entryNumber % 4 == 2) { nameLabel.setColor(Color.MAGENTA); marker.setColor(Color.MAGENTA); } else if (entryNumber % 4 == 3) { nameLabel.setColor(Color.BLACK); marker.setColor(Color.BLACK); } add(nameLabel); add(marker); } }
/*Defines and places the Rent state as a circle */ private void placeRent(int x, int y, int width, int height, Color rentColor) { GOval shape = new GOval(x, y, width, height); shape.setFilled(true); shape.setColor(rentColor); add(shape); }