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

📄 arrowbutton.java

📁 打印管理程序,测试完全通过.windows开发环境.
💻 JAVA
字号:
/*
    $Author: $
    $Date: $
    $Revision: $
    $NoKeywords: $
*/

package jp.co.ntl.awt;

import java.awt.*;

public class ArrowButton extends AbstractGroupButton {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public final static int	LEFT   = 1;
	public final static int	RIGHT  = 2;
	public final static int	TOP    = 3;
	public final static int	BOTTOM = 4;

	private Color 	bg;
	private Color   pushedBg;
	private Color   triColor;
	private Color   disabledTriColor;
    private int     direction;

	public ArrowButton(int direction) {
	    super(null);
	    
	    this.direction = direction;
        
        setToggle(false);
        
		bg	= Color.lightGray;
		pushedBg = Color.gray;
		triColor = Color.black;
		disabledTriColor = bg.brighter();
    }

	//
	//	Paint
	//
	public void update(Graphics g) {
		paint(g);
	}

	public void paint(Graphics g) {
        Dimension d = getSize();
        int width = d.width;
        int height = d.height;
        
		if (pushed) {
    		g.setColor(pushedBg);
			g.fill3DRect(0, 0, width, height, false);
		} else {
    		g.setColor(bg);
			g.fill3DRect(0, 0, width, height, true);
		}
		
		if (isEnabled()) {
            g.setColor(triColor);
        } else {
            g.setColor(disabledTriColor);
        }
        drawTriangle(g, width, height);
    }

	protected void drawTriangle(Graphics g, int width, int height) {
		int[] xp = new int[3];
		int[] yp = new int[3];
//        int heightBase4 = height / 4; 
//        int heightBase2 = height / 2; 
//        int widthBase4 = width / 4;
//        int widthBase2 = width / 2;

		switch(direction) {
		case LEFT:	// left (<)
			xp[0] = (int)((float)width / 4 * 3);   yp[0] = (int)((float)height / 4 * 1);
			xp[1] = (int)((float)width / 4 * 1);   yp[1] = (int)((float)height / 2 * 1);
			xp[2] = (int)((float)width / 4 * 3);   yp[2] = (int)((float)height / 4 * 3);
    		g.fillPolygon(xp, yp, 3);
			break;
		case RIGHT:	// right (>)
			xp[0] = (int)((float)width / 4 * 1);   yp[0] = (int)((float)height / 4 * 1);
			xp[1] = (int)((float)width / 4 * 3);   yp[1] = (int)((float)height / 2 * 1);
			xp[2] = (int)((float)width / 4 * 1);   yp[2] = (int)((float)height / 4 * 3);
    		g.fillPolygon(xp, yp, 3);
			break;
		case TOP:	// top (^)
		/*
			xp[0] = (int)((float)width / 4 * 1);   yp[0] = (int)((float)height / 4 * 3);
			xp[1] = (int)((float)width / 2 * 1);   yp[1] = (int)((float)height / 4 * 1);
			xp[2] = (int)((float)width / 4 * 3);   yp[2] = (int)((float)height / 4 * 3);
		*/
			drawTop(g);
			break;
		case BOTTOM:	// bottom (v)
		/*
			xp[0] = (int)((float)width / 4 * 1);   yp[0] = (int)((float)height / 4 * 1);
			xp[1] = (int)((float)width / 2 * 1);   yp[1] = (int)((float)height / 4 * 3);
			xp[2] = (int)((float)width / 4 * 3);   yp[2] = (int)((float)height / 4 * 1);
		*/
		    drawBottom(g);
		    break;
		}
	}
	
	private void drawTop(Graphics g) {
	    Dimension d = getSize();
	    int min = Math.min(d.width, d.height);
	    if (min < 6) {
	        int baseX = d.width / 2;
	        int baseY = d.height / 2;
            int x = baseX;
            int y = baseY;
            g.drawLine(x, y, x, y);
            x--; y++;
            g.drawLine(x, y, x + 2, y);
        } else if (min < 15) {
	        int baseX = d.width / 2;
	        int baseY = d.height / 2 - 1;
            int x = baseX;
            int y = baseY;
            g.drawLine(x, y, x, y);
            x--; y++;
            g.drawLine(x, y, x + 2, y);
            x--; y++;
            g.drawLine(x, y, x + 4, y);
        } else {
		    int[] xp = new int[3];
		    int[] yp = new int[3];
            int heightBase4 = d.height / 4; 
//            int heightBase2 = d.height / 2; 
            int widthBase4 = d.width / 4;
            int widthBase2 = d.width / 2;
   		    xp[0] = widthBase4;             yp[0] = d.height - heightBase4 - 1;
		    xp[1] = widthBase2;             yp[1] = heightBase4;
		    xp[2] = d.width - widthBase4 - 1; yp[2] = d.height - heightBase4 - 1;
    		g.fillPolygon(xp, yp, 3);
        }
	}
	
	private void drawBottom(Graphics g) {
	    Dimension d = getSize();
	    int min = Math.min(d.width, d.height);
	    if (min < 6) {
	        int baseX = d.width / 2;
	        int baseY = d.height / 2 - 1;
            int x = baseX;
            int y = baseY;
            g.drawLine(x, y, x + 2, y);
            x++; y++;
            g.drawLine(x, y, x, y);
        } else if (min < 15) {
	        int baseX = d.width / 2 - 2;
	        int baseY = d.height / 2 - 1;
            int x = baseX;
            int y = baseY;
            g.drawLine(x, y, x + 4, y);
            x++; y++;
            g.drawLine(x, y, x + 2, y);
            x++; y++;
            g.drawLine(x, y, x, y);
        } else {
		    int[] xp = new int[3];
		    int[] yp = new int[3];
            int heightBase4 = d.height / 4; 
//            int heightBase2 = d.height / 2; 
            int widthBase4 = d.width / 4;
            int widthBase2 = d.width / 2;
		    xp[0] = d.width - widthBase4 - 1; yp[0] = heightBase4 + 1;
		    xp[1] = widthBase2;             yp[1] = d.height - heightBase4 - 1;
		    xp[2] = widthBase4 + 1;         yp[2] = heightBase4 + 1;
    		g.fillPolygon(xp, yp, 3);
        }
	}
}

⌨️ 快捷键说明

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