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

📄 randomline.java

📁 Java程序设计(美) David D. Riley著 机械工业出版社 书籍配套 代码
💻 JAVA
字号:
// Figure 11.4import javax.swing.JComponent;import java.awt.*;public class RandomLine extends JComponent {   private int  x1, y1, x2, y2;	/**	post:	0 <= x1 <= 399  and  0 <= y1 <= 399	 *			and  0 <= x2 <= 399  and  0 <= y2 <= 399	 *			and  getBackground() == Color.black  	 */	public RandomLine()  {		setBounds(0, 0, 400, 400);		x1 = (int)(Math.random()*400);		x2 = (int)(Math.random()*400);		y1 = (int)(Math.random()*400);		y2 = (int)(Math.random()*400);		setBackground(Color.black);	}    	/**	post:	a black line is drawn from (x1,y1) to (x2,y2)	 *			and  the line is colored getBackground() 	 */	public  void  paint(Graphics g)   {		g.setColor( getBackground() );		g.drawLine(x1, y1, x2, y2);	}}

⌨️ 快捷键说明

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