separator.java

来自「打印管理程序,测试完全通过.windows开发环境.」· Java 代码 · 共 61 行

JAVA
61
字号
/*
    $Author: $
    $Date: $
    $Revision: $
    $NoKeywords: $
*/
package jp.co.ntl.awt;

import java.awt.Graphics;
import java.awt.Color;

public class Separator {
	public static final int VERTICAL = 0;
	public static final int HORIZONTAL = 1; 
    private int x;
    private int y;
    private int length;
    private int direction;
    
    public Separator(int x, int y, int length) {
        this.x = x;
        this.y = y;
        this.length = length;
        direction = HORIZONTAL;
    }
    
    public Separator(int x, int y) {
    	this(x, y, 100);
    }
    
    public void setSize(int x, int y, int length) {
    	this.x = x;
    	this.y = y;
    	this.length = length;
    }
    
    public void setLength(int length) {
    	this.length = length;
    }
    
    public void setDirection(int direction) {
    	this.direction = direction;
    }
    
    public void draw(Graphics g, Color color) {
    	if (direction == HORIZONTAL) {
			g.setColor(Color.white);
			g.drawLine(x + 1, y + 1, x + 1 + length, y + 1);
			g.setColor(color);
			g.drawLine(x, y, x + length, y);   		
    	} else if (direction == VERTICAL) {
			g.setColor(Color.white);
			g.drawLine(x + 1, y - 1, x + 1, y - 1 + length);
			//g.setColor(color);
			g.drawLine(x, y, x, y + length);   	    		
    	} else {
    		throw new IllegalArgumentException("wrong argument direction");
    	}
    }
}

⌨️ 快捷键说明

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