driver.java

来自「Java程序设计(美) David D. Riley著 机械工业出版社 书籍配套」· Java 代码 · 共 44 行

JAVA
44
字号
import java.awt.Color;import javax.swing.JFrame;/**	Author: David D. Riley *		Date: Jan, 2005 *   Second prototype for the carterpillar program (Figure 3.26) */public class Driver  {    private  JFrame  theWindow;    private  Oval  head, frontSegment, midSegment, rearSegment;    private  Oval face, leftEye, rightEye, mouth;    private  Rectangle  frontLeg;    public Driver()   {        theWindow = new JFrame( "The Pede" );        theWindow.setBounds(30, 30, 500, 250);        theWindow.setLayout(null);        theWindow.setVisible(true);        head = new Oval( 110, 70, 84, 84 );        theWindow.add(head, 0);        face = new Oval(2, 2, 80, 80);        face.setBackground(Color.white);        head.add(face, 0);        leftEye = new Oval(15, 30, 15, 10);        leftEye. setBackground (Color.blue);        face.add(leftEye, 0);        rightEye = new Oval(50, 30, 15, 10);        rightEye. setBackground (Color.blue);        face.add(rightEye, 0);        mouth = new Oval(25, 50, 30, 10);        face.add(mouth, 0);        mouth. setBackground (Color.red);        frontSegment = new Oval( 180, 100, 50, 50 );        theWindow.add(frontSegment, 0);        frontLeg = new Rectangle(200, 150, 10, 20);        theWindow.add(frontLeg, 0);        midSegment = new Oval( 230, 100, 50, 50 );        theWindow.add(midSegment, 0);        rearSegment = new Oval( 280, 100, 50, 50 );        theWindow.add(rearSegment, 0);        theWindow.repaint();    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?