Re: [問題] Java視窗可以這樣做嗎?

看板java作者 (骨頭)時間18年前 (2007/08/07 19:55), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/4 (看更多)
※ 引述《RWA (基本上我是個演員)》之銘言: : 假設我原有的程式都已完成 : 並且都可以在command line下執行 : 想請問我可以用製作視窗介面的方式 : 製作一個按鈕 當按下去後 就去跑我在command line下的指令 : 例如按下後依序: : 執行 1.java Server ip port : 執行 2.java Client ip port : . : . : 有點像shell script的寫法,而操作方式像php的system("command")呼叫 : 感覺邏輯怪怪的XD 只是想說做出一個視窗讓使用者方便執行程式 : 請問這是可行的嗎? : ps:我有試過寫bat檔,可行 但我只是純粹想用視窗方式完成..:) 這不是很困難的 首先GUI的部份你就自己去努力吧XD 架Frame 用container add button 寫ActionListener 以上簡單帶過 然後你在對應的觸發上面寫上 Runtime相關的處理 http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html 你也可以用bat先寫好 再用Runtime去做 如果你需要另外輸入arg 就先取得exec之後的 Process的輸入串流 如果你需要取得程式跑在畫面上的結果 你就取得Process的輸出串流 我底下附上一個以前用 Runtime操作ipconfig取卡號的sample:P --- import java.io.*; class getMac2{ private String getMacAddressIP(){ String str=""; String macAddress=""; try { //執行 "ipconfig /all " Process pp= Runtime.getRuntime().exec ("ipconfig /all"); //取得輸入串流 InputStreamReader ir = new InputStreamReader( pp.getInputStream()); BufferedReader input = new BufferedReader (ir); //用來判斷是否為區網的網卡號碼 boolean check =false; for (int i = 1; i<100; i++) { str=input.readLine(); if (str!=null){ //通過區網網段 if(str.indexOf("Ethernet adapter")!=-1) check=true; //取得網路卡號碼 if(check&&str.indexOf("Physical Address")!=-1){ macAddress=str.substring(str.indexOf(":")+2,str.length()); break; } } } }catch (IOException ex) {} //回傳 return macAddress; } public static void main(String[] args) { getMac2 getmac; getmac=new getMac2(); String mac=""; mac=getmac.getMacAddressIP(); //輸出 System.out.println(mac); } } --  ▄▅▆▇███▇▆▅▄▃        ╰┼╯─╮ ╮         ◥███████████◣       ╰┼╯=│=│         ◥██████───────    *. ╯  ╯ ╯ の 物 語 .*  ◥███████──────◣ ~ ◢◣             ◢◣  ◥██████───────◤   ◥◤  空白的世界.翼 ◥◤  ◥██▁▂▃▄▅▆▇███▆▅▄▃▂▂telnet://tony1223.no-ip.info -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.134.27.68
文章代碼(AID): #16k5s_0M (java)
文章代碼(AID): #16k5s_0M (java)