java语言的科学与艺术-编程练习3.10

 1 /*
 2  * File:GLineExample.java
 3  * ----------------------
 4  * This program draws a Tic-Tac-Toe board as an illustration
 5  * of the GLine class. The version uses explict coordinate
 6  * values which makes the program difficult to extand or
 7  * maintain. In Chapter 3, you will learn how to constants 
 8  * and expressions to calculate these corrdinate values.
 9  */
10 import acm.graphics.*;
11 import acm.program.*;
12 
13 public class GLineExample extends GraphicsProgram {
14     
15     public void run (){
16         int x = (getWidth() - BOARD_SIZE) / 2;
17         int y = (getHeight() - BOARD_SIZE) / 2;
18         
19         add (new GLine(x,y + BOARD_SIZE / 4.0,x + BOARD_SIZE,y + BOARD_SIZE / 4.0));
20         add (new GLine(x,y + BOARD_SIZE * 3 / 4.0,x + BOARD_SIZE, y + BOARD_SIZE * 3 / 4.0));
21         add (new GLine(x + BOARD_SIZE / 4.0, y, x + BOARD_SIZE  / 4.0, y + BOARD_SIZE));
22         add (new GLine(x + BOARD_SIZE * 3 / 4.0 ,y ,x + BOARD_SIZE * 3 / 4.0, y + BOARD_SIZE));
23     }
24     /*
25      * Private constants
26      */
27     private static final int BOARD_SIZE = 90;
28 }

 

posted on 2012-12-05 15:19  mybluecode  阅读(171)  评论(0编辑  收藏  举报