arrowicon.java
来自「java swing 开发代码」· Java 代码 · 共 50 行
JAVA
50 行
// ArrowIcon.java// A simple implementation of the Icon interface that can make// Up and Down arrows.//package jswing.ch16;import javax.swing.Icon;import java.awt.*;public class ArrowIcon implements Icon { public static final int UP = 0; public static final int DOWN = 1; private int direction; private Polygon pagePolygon = new Polygon(new int[] { 2, 4, 4, 10, 10, 2 }, new int[] { 4, 4, 2, 2, 12, 12}, 6); private int[] arrowX = { 4, 9, 6 }; private Polygon arrowUpPolygon = new Polygon(arrowX, new int[] { 10, 10, 4 }, 3); private Polygon arrowDownPolygon = new Polygon(arrowX, new int[] { 6, 6, 11 }, 3); public ArrowIcon(int which) { direction = which; } public int getIconWidth() { return 14; } public int getIconHeight() { return 14; } public void paintIcon(Component c, Graphics g, int x, int y) { g.setColor(Color.black); pagePolygon.translate(x, y); g.drawPolygon(pagePolygon); pagePolygon.translate(-x, -y); if (direction == UP) { arrowUpPolygon.translate(x, y); g.fillPolygon(arrowUpPolygon); arrowUpPolygon.translate(-x, -y); } else { arrowDownPolygon.translate(x, y); g.fillPolygon(arrowDownPolygon); arrowDownPolygon.translate(-x, -y); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?