triangle.java

来自「Java程序设计(美) David D. Riley著 机械工业出版社 书籍配套」· Java 代码 · 共 25 行

JAVA
25
字号
// (Figure 8.17)import java.awt.Graphics;import javax.swing.JComponent;public class Triangle extends JComponent {	/**		post:	getbackGround() is an invisible color	 *				and  getWidth() == getHeight() == 0 	 */  	public Triangle( )   {		super( );	}		/**	post:	a Triangle is drawn with vertices at (getWidth()/2, 0),	 *					(0, getHeight()-1) and (getWidth()-1, getHeight()-1)	 *			and  the color of thhe triangle is getBackground() 	 */	public  void  paint( Graphics g )   {		g.setColor( getBackground() );		g.drawLine( getWidth()/2, 0, 0, getHeight()-1 );		g.drawLine( 0, getHeight()-1, getWidth()-1, getHeight()-1 );		g.drawLine( getWidth()/2, 0, getWidth()-1, getHeight()-1 );	}}

⌨️ 快捷键说明

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