我尝试更改我通过Eclipse导出的jar文件的显示icon。在网上搜索后,我找到了这段代码:
"frmPos.setIconImage( new imageIcon( getClass().getClassLoader().getResource( "PATH/TO/YourImage.png" ) ) );"
但它不起作用,它给了我这个错误"描述资源路径位置类型 imageIcon无法解析为类型window_layout.java / PostOffice / src第150行Java问题"。谁能告诉我我做错了什么?我是否在错误的位置放置了更改jar图标的代码?下面是我的代码示例。感谢。
import java.awt.EventQueue;
public class window_layout {
private JFrame frmPos;
private ArrayList<Shipment> shipment_list;
private Shipment temp;
private boolean international_destination_bl;
private boolean priority_bl;
private int domestic_counter;
private int international_counter;
private String shipment_type;
private float weight;
private int postal_code;
private String country;
private float domestic_total_cost;
private float international_total_cost;
private int shipments_counter;
private String str_weight = "Βάρος:";
private String text = null;
private boolean JComboBox_bl;
private boolean JComboBox_1_bl;
private boolean JComboBox_2_bl;
private boolean JComboBox_3_bl;
private JFrame border;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextPane textPane_3;
private JTextPane textPane_5;
private JComboBox comboBox;
private JComboBox comboBox_1;
private JComboBox comboBox_2;
private JComboBox comboBox_3;
private JTextField textField_3;
private TextArea messageBox;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
window_layout window = new window_layout();
window.frmPos.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public window_layout()
{
initialize();
shipment_list = new ArrayList<Shipment> ( );
international_destination_bl = false;
domestic_counter = 0;
international_counter = 0;
weight = 0;
postal_code = 0;
domestic_total_cost = 0;
international_total_cost = 0;
shipments_counter = 0;
JComboBox_bl = false;
JComboBox_1_bl = false;
JComboBox_2_bl = false;
JComboBox_3_bl = false;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Initialize the contents of the frame.
private void initialize()
{
frmPos = new JFrame();
frmPos.setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\Christos\\workspace\\PostOffice\\Envelope_64x64.png"));
frmPos.setTitle("e - Post Office");
frmPos.getContentPane().setBackground(new Color(255, 255, 255));
frmPos.setBounds(100, 100, 448, 438);
frmPos.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmPos.getContentPane().setLayout(null);
//*** CODE WHICH CHANGES THE ICON OF THE JAR FILE ***
frmPos.setIconImage( new imageIcon( getClass().getClassLoader().getResource( "Envelope_64x64.png" ) ) );