全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2209
推到 Plurk!
推到 Facebook!

請問JTree是不是沒辦法使用超連結??

答題得分者是:neoart
superhank
一般會員


發表:8
回覆:24
積分:6
註冊:2003-06-30

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-08-07 21:54:57 IP:218.165.xxx.xxx 未訂閱
各位前輩您們好..        我之前用Applet寫了數狀結構...      DefaultMutableTreeNode root = new DefaultMutableTreeNode("world");                              ~~~~~~~~ 我想讓她有連結性(寫個超連結) 但似乎不是在話底線的地方作修改.. 不知道是Java沒辦法這麼做還是我沒找到方法?? 希望各位前輩能給我一些解答..                                  謝謝....
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-08-08 09:20:44 IP:203.73.xxx.xxx 未訂閱
引言: 各位前輩您們好.. 我之前用Applet寫了數狀結構... DefaultMutableTreeNode root = new DefaultMutableTreeNode("world"); ~~~~~~~~ 我想讓她有連結性(寫個超連結) 但似乎不是在話底線的地方作修改.. 不知道是Java沒辦法這麼做還是我沒找到方法?? 希望各位前輩能給我一些解答.. 謝謝.... < face="Verdana, Arial, Helvetica"> superhank 你好: 請參考以下的連結文章
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
neoart
版主


發表:22
回覆:582
積分:425
註冊:2003-05-09

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-08-11 11:07:01 IP:61.64.xxx.xxx 未訂閱
Take a look at the following code of the last class i demostrated for your tree object. Once you click the some nodes in the folder of "Taiwan",the browser will pup-out a browser and display the target content that as programm assigned ======================================================================== import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; import javax.swing.tree.*; public class Applet1 extends Applet { private boolean isStandalone = false; BorderLayout borderLayout1 = new BorderLayout(); JPanel jPanel1 = new JPanel(); BorderLayout borderLayout2 = new BorderLayout(); JTree tree; //Get a parameter value public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } //Construct the applet public Applet1() { } //Initialize the applet public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { this.setLayout(borderLayout1); this.repaint(); System.out.println("finish jbInit"); jPanel1.setLayout(borderLayout2); this.add(jPanel1, BorderLayout.CENTER); //add tree object to panel. DefaultMutableTreeNode root = new DefaultMutableTreeNode("world"); DefaultMutableTreeNode country = new DefaultMutableTreeNode("Taiwan"); root.add(country); DefaultMutableTreeNode state = new MyNodeElement("taiwan","http://delphi.ktop.com.tw"); country.add(state); DefaultMutableTreeNode city = new MyNodeElement("one","http://java.sun.com"); state.add(city); city = new MyNodeElement("two","http://www.jsptw.com"); state.add(city); state = new DefaultMutableTreeNode("three"); country.add(state); city = new DefaultMutableTreeNode("four"); state.add(city); country = new DefaultMutableTreeNode("five"); root.add(country); state = new DefaultMutableTreeNode("six"); country.add(state); city = new DefaultMutableTreeNode("seven"); state.add(city); tree = new JTree(root); jPanel1.add(tree,BorderLayout.CENTER); tree.addMouseListener(new Applet1_tree_mouseAdapter(this)); } //Get Applet information public String getAppletInfo() { return "Applet Information"; } //Get parameter info public String[][] getParameterInfo() { return null; } void tree_mouseClicked(MouseEvent e) { TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); if(selPath == null) return; if(tree.getLastSelectedPathComponent() instanceof MyNodeElement){ //註,用type identification不是個好習慣.不過我目前只知道這樣用罷了. MyNodeElement myNode=(MyNodeElement)tree.getLastSelectedPathComponent(); try{ getAppletContext().showDocument( new java.net.URL( myNode.getTargetUrl()), "_blank");//"_blank" 是你要顯示的target frame,省略的話,就是目前applet所在的frame了 }catch(Exception exp){ exp.printStackTrace(); } } } } class MyNodeElement extends DefaultMutableTreeNode{ String urlstring; MyNodeElement(String displayString,String urlString){ super(displayString); urlstring=urlString; } String getTargetUrl(){return urlstring;} } class Applet1_tree_mouseAdapter extends java.awt.event.MouseAdapter { Applet1 adaptee; Applet1_tree_mouseAdapter(Applet1 adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.tree_mouseClicked(e); } } ================================================================= hope it helps your need.
superhank
一般會員


發表:8
回覆:24
積分:6
註冊:2003-06-30

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-08-11 12:33:46 IP:218.165.xxx.xxx 未訂閱
由程式碼來看.. 應該就是我要的了.. 但是我complier完卻沒辦法執行ㄝ. 會出現以下訊息:Exception in thread "main" java.lang.NoSuchMethodError: main        P.s 和上次一樣必須用網頁顯示...                                  多謝指點迷津...  
superhank
一般會員


發表:8
回覆:24
積分:6
註冊:2003-06-30

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-08-11 12:35:40 IP:218.165.xxx.xxx 未訂閱
引言:
引言: 各位前輩您們好.. 我之前用Applet寫了數狀結構... DefaultMutableTreeNode root = new DefaultMutableTreeNode("world"); ~~~~~~~~ 我想讓她有連結性(寫個超連結) 但似乎不是在話底線的地方作修改.. 不知道是Java沒辦法這麼做還是我沒找到方法?? 希望各位前輩能給我一些解答.. 謝謝.... < face="Verdana, Arial, Helvetica"> superhank 你好: 請參考以下的連結文章 >< face="Verdana, Arial, Helvetica"> 謝謝您... 讓我對這東西有多一份了解...
superhank
一般會員


發表:8
回覆:24
積分:6
註冊:2003-06-30

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-08-11 12:43:49 IP:218.165.xxx.xxx 未訂閱
謝謝各位前輩.. 我懂了.. 我已經解決此問題了.. 非常感謝neaort前輩...
系統時間:2024-05-18 14:09:17
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!