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

📄 diamondabstractbuttonstateicon.java

📁 The Definitive Guide to Java Swing, Third Edition by John Zukowski (Author) 源码
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;

public class DiamondAbstractButtonStateIcon implements Icon {
  private final int width = 10;
  private final int height = 10;
  private Color color;
  private Polygon polygon;
  public DiamondAbstractButtonStateIcon(Color color) {
    this.color = color;
    initPolygon();
  }
  private void initPolygon() {
    polygon = new Polygon();
    int halfWidth = width/2;
    int halfHeight = height/2;
    polygon.addPoint (0, halfHeight);
    polygon.addPoint (halfWidth, 0);
    polygon.addPoint (width, halfHeight);
    polygon.addPoint (halfWidth, height);
  }
  public int getIconHeight() {
    return width;
  }
  public int getIconWidth() {
    return height;
  }
  public void paintIcon(Component component, Graphics g, int x, int y) {
    boolean selected = false;
    g.setColor (color);
    g.translate (x, y);
    if (component instanceof AbstractButton) {
      AbstractButton abstractButton = (AbstractButton)component;
      selected = abstractButton.isSelected();
    }
    if (selected) {
      g.fillPolygon (polygon);
    } else {
      g.drawPolygon (polygon);
    }
    g.translate (-x, -y);
  }
}

⌨️ 快捷键说明

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