好的,所以我得到了一个静态的ImageIcon,而Image却没有显示出来。在同一个程序中我使用其他ImagesIcon,但它们不是静态的,所以当我声明它们时,我这样做:
public ImageIcon blabla = new ImageIcon(getClass().getResource(blabla.png));
但是,如果我声明一个ImageIcon静态我不能使用该行,因为无法从静态值访问getClass()。现在这些图像没有显示出来:
public static ImageIcon blabla = new ImageIcon(blabla.png);
感谢您的帮助!
public static ImageIcon networkOfflineIcon = new ImageIcon("Images/networkOfflineIcon.png");
public static ImageIcon networkIcon = new ImageIcon("Images/networkIcon.png");
protected static JMenuItem jmiRemote = new JMenuItem(" Remote", networkOfflineIcon);
//************************************************************************
public static void changeNetWorkStatus(boolean network_status)
//************************************************************************
{
if(network_status){
Application.jmiRemote.setIcon(networkIcon);
Application.jmiRemote.setText("NetWork Online/Remote is On");
Application.lockScreenRemote();
}else if(!network_status){
Application.jmiRemote.setIcon(networkOfflineIcon);
Application.jmiRemote.setText("NetWork Offline/Remote is Off");
Application.unlockScreenRemote();
}
}//DOESNT CHANGE THE IMAGE
//************************************************************************
答案 0 :(得分:4)
在静态上下文中,您可以写:
public ImageIcon imageIcon = new ImageIcon(MyClass.class.getResource("icon.png"));