📄 driver.java
字号:
import javax.swing.*;import java.awt.TextArea;/** Program to measure distance traveled due to gravity (Figure 10.13) * Author: David Riley * Date: January, 2005 */public class Driver { private JFrame window; private TextArea outPane; private HeightField inField; private JLabel label; /** post: window != null and outPane != null and inField!=null * and outPane, inField are both displayed in window */ public Driver() { window = new JFrame("Gravity Demo"); window.setBounds(10, 10, 400, 230); window.setVisible(true); window.setLayout(null); outPane = new TextArea(); outPane.setBounds(50, 50, 340, 150); window.add(outPane, 0); label = new JLabel("Initial Height:"); label.setBounds(10, 10, 100, 25); window.add(label, 0); inField = new HeightField(110, 10, this); window.add(inField, 0); window.repaint(); } /** pre: h > 0 and outPane != null <br> * post: outPane is reset to contain one line for each second of * drop from a height of h until through last height before * zero. Each line gives the height of the dropped object * and its velocity at that second. */ public void displayFall( int h ) { int seconds; outPane.setText(""); // clear the text area of prior content seconds = 0; while ( h-seconds*seconds*4.9 > 0 ) { outPane.append("Time: " + seconds +" sec. "); outPane.append("Height: "+(int)(h-seconds*seconds*4.9)+"m."); outPane.append(" Velocity: " + seconds*9.81 + "\n"); seconds++; } outPane.repaint(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -