driver.java
来自「Java程序设计(美) David D. Riley著 机械工业出版社 书籍配套」· Java 代码 · 共 57 行
JAVA
57 行
import java.awt.Color;import javax.swing.JFrame;/** Author: David D. Riley * Date: Jan, 2005 * Happy Faces Program (Figure 4.14) */ public class Driver { private JFrame theWindow; private Oval topLeftFace, topRightFace, botLeftFace, botRightFace; /** post: a window with four happy faces is drawn */ public Driver() { theWindow = new JFrame("The Window"); theWindow.setBounds(10, 10, 250, 250); theWindow.setLayout(null); theWindow.setBackground(Color.white); theWindow.setVisible(true); topLeftFace = new Oval(30, 10, 100, 100); makeHappyFace(topLeftFace); theWindow.add(topLeftFace, 0); topLeftFace.repaint(); topRightFace = new Oval(140, 10, 100, 100); makeHappyFace(topRightFace); theWindow.add(topRightFace, 0); topRightFace.repaint(); botLeftFace = new Oval(30, 120, 100, 100); makeHappyFace(botLeftFace); theWindow.add(botLeftFace, 0); botLeftFace.repaint(); botRightFace = new Oval(140, 120, 100, 100); makeHappyFace(botRightFace); theWindow.add(botRightFace, 0); botRightFace.repaint(); } /** pre: f has been constructed with a radius of 100 * post: f is colored yellow * and two black eyes are added to f * and a black smile is added to f */ private void makeHappyFace( Oval f ) { Oval leftEye, rightEye, mouth, mouthCover; f.setBackground( Color.yellow ); mouth = new Oval( 20, 20, 60, 60 ); f.add(mouth, 0); mouthCover = new Oval( -10, -30, 80, 80 ); mouthCover.setBackground(Color.yellow); mouth.add(mouthCover, 0); leftEye = new Oval( 20, 30, 15, 15 ); f.add(leftEye, 0); rightEye = new Oval( 65, 30, 15, 15); f.add(rightEye, 0); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?