driver.java
来自「Java程序设计(美) David D. Riley著 机械工业出版社 书籍配套」· Java 代码 · 共 39 行
JAVA
39 行
import java.awt.Color;import javax.swing.JFrame;/** Author: David D. Riley * Date: Jan, 2005 * Three Squares Program (Figure 4.10) */public class Driver { private JFrame theWindow; private Rectangle leftSquare, midSquare, rightSquare; /** post: a window with three blue filled squares is drawn */ public Driver() { theWindow = new JFrame("The Window"); theWindow.setBounds(10, 10, 450, 250); theWindow.setLayout(null); theWindow.setBackground(Color.white); theWindow.setVisible(true); leftSquare = new Rectangle(100, 100, 50, 50); colorAndAdd(leftSquare, Color.blue); midSquare = new Rectangle(200, 100, 50, 50); colorAndAdd(midSquare, Color.blue); rightSquare = new Rectangle(300, 100, 50, 50); colorAndAdd(rightSquare, Color.blue); } /** pre: w has been instantiated * and r has been instantiated * and c is a valid Color * post: r is set to color c * and r is added to theWindow */ private void colorAndAdd(Rectangle r, Color c) { r.setBackground(c); theWindow.add(r, 0); r.repaint(); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?