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

📄 driver.java

📁 Java程序设计(美) David D. Riley著 机械工业出版社 书籍配套 代码
💻 JAVA
字号:
import java.awt.Color;import java.awt.event.*;import javax.swing.*;/** Marquee lights program  (Figure 12.7) *  Author: David D. Riley *  Date:   January, 2005 */public class Driver implements ActionListener{	private	Oval[] dots;	private	JFrame window;		/** post:	window is created 	 *			and a row of filled ovals is assigned to dots	 *				(These ovals span the window horizontally.)	 *			and any dot with a multiple of 3 for an index	 *				is dark gray, while all other dots are white.  	 */	public Driver()  { 		window = new JFrame("Marquee Lights");		window.setBounds(10, 10, 600, 500);		window.setVisible(true);		window.setLayout(null);		window.setBackground(Color.black);			JButton button = new JButton("Click to change light colors.");			button.setBounds(100, 420, 400, 30);			button.addActionListener(this);			window.add(button, 0); 		int xPos = 5;		dots = new Oval[32];		for  ( int j=0; j!=32; j++ )   {			dots[j] = new Oval(xPos, 100, 10, 10);			if ( j % 3 == 0 )   {				dots[j].setBackground( Color.darkGray );			} else {				dots[j].setBackground( Color.white );			}			window.add(dots[j], 0);			xPos = xPos + 15;		}		window.repaint();	}		/**	post:	all dot's old colors are moved to the left by one dot	 *			and the rightmost dot gets the previous color of 	 *			the leftmost dot 	 */	public void actionPerformed(ActionEvent e)   {		Color leftmostDotColor;		leftmostDotColor = dots[0].getBackground();		for  ( int j=0; j!=31; j++ )   {			dots[j].setBackground( dots[j+1].getBackground() );		}		dots[31].setBackground( leftmostDotColor );		window.repaint();	}}

⌨️ 快捷键说明

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