⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shapecanvas.java

📁 包括Rect,Circle两个类
💻 JAVA
字号:

// 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -