How to run the Jar well?
来源:互联网 发布:linux查找大文件命令 编辑:程序博客网 时间:2024/05/16 01:27
This problem has puzzled me for nearly three days...
As I don't know even this kind of thing would happen at the first place...
About how to display the picture, if i write the related codes like this:
aquariumImage = Toolkit.getDefaultToolkit().getImage("bubbles.gif");
it can be run well in the eclipse but in the jar.
so I change it into this by adding URL :
URL address = getClass().getResource("bubbles.gif");
aquariumImage = Toolkit.getDefaultToolkit().getImage(address);
it then works perfectly.
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.URL;
public class Test extends Frame
...{
private static final long serialVersionUID = 1L;
static Image aquariumImage;
public Test()
...{
addWindowListener(new WindowAdapter()
...{
public void windowClosing(WindowEvent e)
...{
dispose();
System.exit(0);
}
});
}
public static void main(String[] args)
...{
Test test = new Test();
test.go();
test.setSize(600, 435);
test.setVisible(true);
Graphics g = test.getGraphics();
while (!g.drawImage(aquariumImage, 0, 0, test));
}
public void go()
...{
URL address = getClass().getResource("bubbles.gif");
aquariumImage = Toolkit.getDefaultToolkit().getImage(address);
}
}
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.URL;
public class Test extends Frame
...{
private static final long serialVersionUID = 1L;
static Image aquariumImage;
public Test()
...{
addWindowListener(new WindowAdapter()
...{
public void windowClosing(WindowEvent e)
...{
dispose();
System.exit(0);
}
});
}
public static void main(String[] args)
...{
Test test = new Test();
test.go();
test.setSize(600, 435);
test.setVisible(true);
Graphics g = test.getGraphics();
while (!g.drawImage(aquariumImage, 0, 0, test));
}
public void go()
...{
URL address = getClass().getResource("bubbles.gif");
aquariumImage = Toolkit.getDefaultToolkit().getImage(address);
}
}
- How to run the Jar well?
- How to run a jar
- How to Run the OnScreenKeyboard
- How to Run a .Jar Java File
- How to execute the jar
- How To Use the C Run-Time
- How to Run Hadoop in the Cloud
- How to use english well!
- How to test if the server is configured well to send email to external accoun
- How to run the qualcomm AR samples on Android
- How to run through the service reset procedure
- How to Re-Run the OS X Setup Assistant
- how to run couchDB
- How to run Conda?
- how to get the android extra support jar
- 【技能库】--spring boot , how to run web app jar(168)
- How to run thing locally
- How to protect your accounts' passwords and remember them well
- prototype.js 的ajax.update调用时,执行包含的js
- javascript中的Function对象
- 转一下源代码
- MenuBrowser
- ArcGIS 9.2 笔记(3):三维功能
- How to run the Jar well?
- ArcGIS 9.2 笔记(4):数据互操作
- C++内存管理变革(3):另类内存管理
- 2007年CSDN网最实用文章是什么?
- 回忆的片断(截取)2006
- sql server 面试时 的考题!!(整理)
- 使用基本的ASP.NET服务器端控件的综合实例
- 虎皮辣椒三式
- Unable to find a javac compiler;Perhaps JAVA_HOME does not point to the JDK异常产生原因和解决方法。