boundedshape.java

来自「一个简单的JAVA绘图程序」· Java 代码 · 共 49 行

JAVA
49
字号
//********************************************************************
//  BoundedShape.java     Author: Lewis and Loftus / Peter DePasquale
//
//  Refinement #2
//
//  Represents any shape defined by a bounding rectangle.
//********************************************************************

import java.io.*;
import java.awt.*;

abstract class BoundedShape extends Shape
{
   protected Point upperLeft;
   protected int width, height;

   //-----------------------------------------------------------------
   //  Sets the color, position, and size of the shape.
   //-----------------------------------------------------------------
   public BoundedShape (Color color, Point corner, int wide, int high)
   {
      strokeColor = color;
      upperLeft = corner;
      width = wide;
      height = high;
   }

   //-----------------------------------------------------------------
   //  Sets the upper left point and the size of the shape. Allows
   //  for dragging in multiple directions.
   //-----------------------------------------------------------------
   public void setShape (Point firstPt, Point currentPt)
   {
      if (firstPt.x <= currentPt.x)
         if (firstPt.y <= currentPt.y)
            upperLeft = firstPt;
         else
            upperLeft = new Point (firstPt.x, currentPt.y);
      else
         if (firstPt.y <= currentPt.y)
            upperLeft = new Point (currentPt.x, firstPt.y);
         else
            upperLeft = currentPt;

      width = Math.abs (currentPt.x - firstPt.x);
      height = Math.abs (currentPt.y - firstPt.y);
   }
}

⌨️ 快捷键说明

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