⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 driver.java

📁 Java程序设计(美) David D. Riley著 机械工业出版社 书籍配套 代码
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -