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

📄 line.java

📁 Java程序设计(美) David D. Riley著 机械工业出版社 书籍配套 代码
💻 JAVA
字号:
import javax.swing.*;import java.awt.*;public class Line extends JComponent  {    private boolean isMajorDiagonal;	public Line(int x1, int y1, int x2, int y2)  {        super();        setBounds(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1-x2)+1, Math.abs(y1-y2)+1);        setBackground(Color.black);        isMajorDiagonal = (x1==Math.min(x1,x2) && y1==Math.min(y1,y2)) || (x2==Math.min(x1,x2) && y2==Math.min(y1,y2));         	}    /**   postconditon            this method draws a line segment from point (getX(),getY()) to point             (x2, y2) in the background coordinate system and with  color from getBackground() */    public void paint(Graphics g)  {        g.setColor( getBackground() );        if (isMajorDiagonal)            g.drawLine(0, 0, getWidth()-1, getHeight()-1);        else            g.drawLine(0, getHeight()-1, getWidth()-1, 0);   }}

⌨️ 快捷键说明

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