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

📄 driver.java

📁 Java程序设计(美) David D. Riley著 机械工业出版社 书籍配套 代码
💻 JAVA
字号:
import javax.swing.*;import java.awt.*;/** Program to animate a message moving side to side in a window  (Figure 8.38) *  Author: David Riley *  Date: January, 2005  */public class Driver  {	private JFrame window;	private Label fishyMsg;	private MsgCallbackTimer clock;	private int velocity;	/**	post:	window != null 	 *				and fishyMsg is placed at the left edge of window	 *				and velocity = 2	 *				and clock is scheduled for 1/50 sec. repeated events 	 */	public Driver()   {		window = new JFrame("Animated Message");		window.setBounds(10, 10, 400, 200);		window.setVisible(true);		window.setLayout(null);		fishyMsg = new Label("FISH");		fishyMsg.setBounds(0, 70, 50, 30);		fishyMsg.setForeground(Color.black);		fishyMsg.setBackground(Color.blue);		window.add(fishyMsg, 0); 		window.repaint();		velocity = 1;		clock = new MsgCallbackTimer(20, this);		clock.start();	}	/**	pre:	fishyMsg != null  <br>	 *		post:	(either the left or right edge of fishyMsg@pre lies	 *				outside the boundaries of pane)  	 *  						implies velocity == - velocity@pre	 *				and  fishyMsg.getX() == fishyMsg.getX()@pre + velocity 	 */	public void moveMsg( )   {		if (fishyMsg.getX() < 0			|| fishyMsg.getX()+fishyMsg.getWidth() > window.getWidth())		{			velocity = -velocity;		}		fishyMsg.setLocation( fishyMsg.getX()+velocity, fishyMsg.getY() );	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -