java语言的科学与艺术-编程练习2.9
1 /* 2 * File:Rainbow.java 3 * --------------- 4 * This program draws a rainbow 5 */ 6 import acm.graphics.*; 7 import acm.program.*; 8 import java.awt.*; 9 public class Rainbow extends GraphicsProgram { 10 11 public void run(){ 12 /*blackground*/ 13 GRect rect = new GRect(0,0,1500,1000); 14 15 GOval oval1 = new GOval(-130,80,1000,1000); 16 GOval oval2 = new GOval(-120,90,980,980); 17 GOval oval3 = new GOval(-110,100,960,960); 18 GOval oval4 = new GOval(-100,110,940,940); 19 GOval oval5 = new GOval(-90,120,920,920); 20 GOval oval6 = new GOval(-80,130,900,900); 21 GOval oval7 = new GOval(-70,140,880,880); 22 23 24 /* 25 * set colors of rainbow 26 */ 27 oval1.setColor(Color.RED); 28 oval2.setColor(Color.ORANGE); 29 oval3.setColor(Color.YELLOW); 30 oval4.setColor(Color.GREEN); 31 oval5.setColor(Color.BLUE); 32 oval6.setColor(Color.MAGENTA); 33 oval7.setColor(Color.CYAN); 34 35 oval1.setFilled(true); 36 oval2.setFilled(true); 37 oval3.setFilled(true); 38 oval4.setFilled(true); 39 oval5.setFilled(true); 40 oval6.setFilled(true); 41 oval7.setFilled(true); 42 43 rect.setColor(Color.CYAN); 44 rect.setFilled(true); 45 add (rect); 46 add (oval1); 47 add (oval2); 48 add (oval3); 49 add (oval4); 50 add (oval5); 51 add (oval6); 52 add (oval7); 53 54 } 55 }
posted on 2012-12-02 20:48 mybluecode 阅读(189) 评论(0) 编辑 收藏 举报