📄 cube.java
字号:
// (Figure 8.21)import java.awt.Graphics;import javax.swing.JComponent;public class Cube extends JComponent { /** post: getbackGround() is an invisible color * and getX() == x and getY() == y * and getWidth() == getHeight() == s */ public Cube(int x, int y, int s) { super( ); setBounds(x, y, s, s); } /** pre: getWidth() == getHeight() * post: a cube is drawn with vertices at (getWidth()/2, 0), * (0, getHeight()-1) and (getWidth()-1, getHeight()-1) * and the color of the triangle is getBackground() */ public void paint( Graphics g ) { int s = getWidth()-1; g.setColor( getBackground() ); g.drawRect(0, s/4, s*3/4, s*3/4); g.drawLine(0, s/4, s/4, 0); //left diagonal line g.drawLine(s*3/4, s/4, s, 0); //right top diagonal line g.drawLine(s/4, 0, s, 0); //top horizontal line g.drawLine(s*3/4, s, s, s*3/4); //right bottom diagonal line g.drawLine(s, 0, s, s*3/4); //back vertical line g.setColor( getForeground() ); g.fillOval(s/4, s/2, s/4, s/4); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -