演示代碼:
在Eclipse開發一個demo
- package cn.test.gui;
-
- import java.awt.Frame;
- import java.awt.event.WindowAdapter;
- import java.awt.event.WindowEvent;
-
- public class GuiDemo {
- private Frame frame;
-
- public GuiDemo() {
- init();
-
- }
-
- /**
- * 初始化gui
- */
- private void init() {
-
- frame = new Frame("我是標題");
- frame.setBounds(100, 100, 400, 200);
- frame.setVisible(true);
- frame.addWindowListener(new WindowAdapter() {
-
- @Override
- public void windowClosing(WindowEvent e) {
- System.out.println("關閉");
- System.exit(0);
- }
-
- });
- }
-
- }
test測試類
- package cn.test.gui;
-
- public class Test {
-
- public static void main(String[] args) {
-
- GuiDemo demo = new GuiDemo();
- }
-
- }
運行結果
只選擇src下的即可
next——next——
選擇主函數所在類文件
完成導入
右鍵設置打開jar文件方式
默認——找到jre-bin-javaw.exe文件 ---打開---確定
在Windows開始菜單的搜索框中輸入“regedit”,在上方搜索出的文件regedit上點擊鼠標右鍵,在彈出的菜單中選擇“以管理員身份運行”。
在註冊表編輯器中,找到“HKEY_CLASSES_ROOT\Applications\javaw.exe\shell\open\command”,在其中文件打開命令中加入參數“-jar”(無引號),修改後的數值類似:“"C:\Program Files\Java\jre7\bin\javaw.exe" -jar "%1"”(只需要添加-jar參數,無需修改其他信息),保存並退出註冊表編輯器。
確認保存即可
運行演示 雙擊程序
完成