shapecanvas.java
来自「包括Rect,Circle两个类」· Java 代码 · 共 47 行
JAVA
47 行
// ShapeCanvas: manages shapes that can move right and act
import java.awt.*;
public class ShapeCanvas extends Canvas
{
private Shape shapes[];
public static final int numShapes = 3;
public ShapeCanvas()
{
setBackground( Color.white );
setSize( 300, 300 );
shapes = new Shape[3];
shapes[0] = new Face( 50, 50, 20 );
shapes[1] = new Rect( 150, 50, 20,30 );
shapes[2] = new Face( 50, 150, 20 ); // update this line to be some other shape
}
public void moveRight()
{
for( int i = 0; i < numShapes; i++ )
{
shapes[i].moveRight();
}
repaint();
}
public void act()
{
for( int i = 0; i < numShapes; i++ )
{
shapes[i].act();
}
repaint();
}
public void paint( Graphics g )
{
for( int i = 0; i < numShapes; i++ )
{
shapes[i].draw( g );
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?