line.java
来自「一个简单的JAVA绘图程序」· Java 代码 · 共 46 行
JAVA
46 行
//********************************************************************
// Line.java Author: Lewis and Loftus / Peter DePasquale
//
// Refinement #2
//
// Represents a line shape in the PaintBox application.
//********************************************************************
import java.io.*;
import java.awt.*;
public class Line extends Shape
{
protected Point firstPoint;
protected Point secondPoint;
//-----------------------------------------------------------------
// Sets up the line with a particular position and color.
//-----------------------------------------------------------------
public Line (Color color, Point p1, Point p2)
{
strokeColor = color;
firstPoint = p1;
secondPoint = p2;
}
//-----------------------------------------------------------------
// Sets the second point of the line.
//-----------------------------------------------------------------
public void setEndPoint (Point endPoint)
{
secondPoint = endPoint;
}
//-----------------------------------------------------------------
// Draws the line.
//-----------------------------------------------------------------
public void draw (Graphics page)
{
page.setColor (strokeColor);
page.drawLine (firstPoint.x, firstPoint.y, secondPoint.x,
secondPoint.y);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?