English 中文(简体)
是否为静态图像集找到 Class (). getRe资源 () 的替代方案?
原标题:Is there an alternative to getClass().getResource() for a Static ImageIcon

OK,所以我有一个静态图像 Icon 和图像只是没有出现。在同一程序里,我用的是其它图像Icon,但是它们不是静态的,所以当我宣布它们的时候,我这样做是这样的:

public ImageIcon blabla = new ImageIcon(getClass().getResource(blabla.png)); 

但如果我宣布一个图像Icon Static I 不能使用该直线, 因为无法从静态值中获取 Class () 。 现在这些图像并没有使用此方法出现 :

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
//************************************************************************
最佳回答

在静态背景下,您可以写:

public ImageIcon imageIcon = new ImageIcon(MyClass.class.getResource("icon.png"));

或者,尝试ImagiIO.read(新文件(“icon.png”))

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签