grectangle.java

来自「一个用JAVA 写的程序」· Java 代码 · 共 53 行

JAVA
53
字号

import java.awt.*;

/** Class to construct a single rectangle
 */
public class GRectangle
{
    private int xCoord, yCoord;
    private int width, height;
    private Color choice;

     /** creates rectangle with given position, dimensions and colour
      * @param initHeight Vertical dimension of rectangle
      * @param initX x coordinate of top left hand corner
      * @param initY y coordinate of top left hand corner
      * @param initWidth Horizontal dimension of rectangle
      * @param initColor colour of rectangle
      */    
    public GRectangle(int initX, int initY, int initWidth, int initHeight, Color initColor)
    {
        xCoord = initX;
        yCoord = initY;
        width = initWidth;
        height = initHeight;
        choice = initColor;
    }
	 
	 public void displayLine(Graphics g)
	 {
		 g.setColor (choice);
		 g.drawRect(xCoord, yCoord, width, height);
	 }
	 
	 public void displayOutline(Graphics g)
	 {
		 g.setColor (choice);
		 g.drawRect(xCoord, yCoord, width, height);
	 }
	
    
    /** displays a rectangle filled in a given colour
     * @param g the graphics object of the frame
     */    
    public void displayFilled (Graphics g)
    {
        g.setColor(choice);
        g.fillRect(xCoord, yCoord, width, height);
    }
 

}
		
		

⌨️ 快捷键说明

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