📄 driver.java
字号:
import javax.swing.JFrame;import java.awt.*;/** Program to print widths of parent Containers (Figure 14.12) * Author: David Riley * Date: January, 2005 */public class Driver { public Driver() { JFrame win = new JFrame("Ancestor Containers"); win.setBounds(10, 10, 400, 70); win.setVisible(true); win.setLayout(null); Rectangle outerRect = new Rectangle( 0, 0, 350, 40 ); outerRect.setBackground(Color.blue); win.add(outerRect, 0); Rectangle midRect = new Rectangle( 0, 0, 250, 30 ); midRect.setBackground(Color.green); outerRect.add(midRect, 0); Rectangle innerRect = new Rectangle( 0, 0, 100, 20 ); innerRect.setBackground(Color.red); midRect.add(innerRect, 0); win.repaint(); displayAncestorWidths( innerRect, win.getContentPane() ); } /** post: all ancestor widths are displayed * - most distant ancestors first */ private void displayAncestorWidths(Component c, Container pane) { if (c != pane && c != null) displayAncestorWidths( c.getParent(), pane ); System.out.println( "Width: " + c.getWidth() ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -