uptriangle.java
来自「Java程序设计(美) David D. Riley著 机械工业出版社 书籍配套」· Java 代码 · 共 23 行
JAVA
23 行
import javax.swing.JComponent;import java.awt.*;public class UpTriangle extends JComponent { /** post: getX() == x-h/2 and getY() == y+h/2 * and getWdith()==h/2 and getHeight()==h/2 */ public UpTriangle(int x, int y, int h ) { super(); setBounds(x-h/4, y-h, h/2, h/2); } /** post: a black triangle is drawn with apex at the top * center and the lower left and right corners of * the bounding rectangle */ public void paint(Graphics g) { g.setColor(Color.black); g.drawLine(getWidth()/2, 0, getWidth()-1, getHeight()-1); g.drawLine(getWidth()-1, getHeight()-1, 0, getHeight()-1); g.drawLine(0, getHeight()-1, getWidth()/2, 0); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?