rect.java

来自「包括Rect,Circle两个类」· Java 代码 · 共 38 行

JAVA
38
字号

// Rect:  Rectangle that may be drawn filled

import java.awt.*;

public class Rect extends Shape
{
   private int height, width;
   private boolean filled;
   
   public Rect( int x, int y, int h, int w )
   {
	  super( x, y );
	  height = h;
	  width = w;
	  filled = false;
   }
   
   public void act()
   {
	   filled = !filled;
   }

   public void draw( Graphics g )
   {
	  if ( filled )
	  {
		 g.setColor( Color.yellow );
         g.fillRect( xpos, ypos, width, height ); 
		 g.setColor( Color.black );
	  }
	  else
	  {
         g.drawRect( xpos, ypos, width, height );
	  }
   }
}

⌨️ 快捷键说明

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