如何根据按下的按钮实例化不同大小的图标 java

how to instantiate different size icons based on the button pressed java

如何更改基于方法中按下的按钮实例化的图标的大小。

例如,这就是按钮实例化的内容

private ExitProgramAction exitProgramAction = new ExitProgramAction("Quit",
      Resources.getIcon("exit16"), "Quit HEAT", new Integer(KeyEvent.VK_Q),
      KeyStroke.getKeyStroke(KeyEvent.VK_Q, java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));

但我试图在单击时通过以下方法(我为其创建按钮)更改 getIcon()。

protected class ZoomButtonAction extends AbstractAction {
    public ZoomButtonAction(String text, String desc)
    {
        super(text);
        putValue(SHORT_DESCRIPTION, desc);
    }

    public void actionPerformed(ActionEvent e){


    }
}

您可以随时使用以下代码调整图标大小。

protected class ZoomButtonAction extends AbstractAction {
    public ZoomButtonAction(String text, String desc)
    {
        super(text);
        putValue(SHORT_DESCRIPTION, desc);
    }

    public void actionPerformed(ActionEvent e){

        ImageIcon icon = (ImageIcon)getValue(Action.SMALL_ICON);
        Image newImage = icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH);
        putValue(Action.SMALL_ICON, new ImageIcon(newImage));
    }
}