downtriangle.java

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

JAVA
25
字号
// Figure 14.21import javax.swing.JComponent;import java.awt.*;public class DownTriangle extends JComponent  {	/**	post:	getX() == x-h/2  and  getY() == y+h/2	 *          and getWdith()==h/2  and  getHeight()==h/2 	 */	public DownTriangle(int x, int y, int h )   {		super();		setBounds(x-h/4, y+h/2, h/2, h/2);	}		/**	post:	a black triangle is drawn with vertices at upper	 *          left, upper right and center bottom of the 	 *          bounding rectangle 	 */	public void paint(Graphics g)   {		g.setColor(Color.black);		g.drawLine(0, 0, getWidth()-1, 0);		g.drawLine(0, 0, getWidth()/2, getHeight()-1);		g.drawLine(getHeight()-1, 0, getWidth()/2, getHeight()-1);	}}

⌨️ 快捷键说明

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