[Java 問題] 已編譯好的JTree無法再網頁上顯示 |
答題得分者是:neoart
|
superhank
一般會員 發表:8 回覆:24 積分:6 註冊:2003-06-30 發送簡訊給我 |
|
neoart
版主 發表:22 回覆:582 積分:425 註冊:2003-05-09 發送簡訊給我 |
|
superhank
一般會員 發表:8 回覆:24 積分:6 註冊:2003-06-30 發送簡訊給我 |
以下是樹的source code.. import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*; public class atree
{
public static void main(String[] args)
{
JFrame frame=new atreeFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class atreeFrame extends JFrame
{
public atreeFrame()
{
setTitle("atree");
setSize(WIDTH,HEIGHT); DefaultMutableTreeNode root
=new DefaultMutableTreeNode("world");
DefaultMutableTreeNode country
=new DefaultMutableTreeNode("Taiwan");
root.add(country);
DefaultMutableTreeNode state
=new DefaultMutableTreeNode("tainan");
country.add(state);
DefaultMutableTreeNode city
=new DefaultMutableTreeNode("one");
state.add(city);
city=new DefaultMutableTreeNode("two");
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); JTree tree = new JTree(root);
Container contentPane = getContentPane();
contentPane.add(new JScrollPane(tree));
} private static final int WIDTH=300;
private static final int HEIGHT=200;
}
謝謝您花時間幫我解答此問題... 發表人 -
|
superhank
一般會員 發表:8 回覆:24 積分:6 註冊:2003-06-30 發送簡訊給我 |
|
neoart
版主 發表:22 回覆:582 積分:425 註冊:2003-05-09 發送簡訊給我 |
既然是在applet用的.我改寫如下,希望可以幫上忙(at least,it works)
以下是applet code:
=======================================
package applettest;
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();
//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 DefaultMutableTreeNode("tainan");
country.add(state);
DefaultMutableTreeNode city
= new DefaultMutableTreeNode("one");
state.add(city);
city = new DefaultMutableTreeNode("two");
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);
JTree tree = new JTree(root);
jPanel1.add(tree,BorderLayout.CENTER);
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
}
============================================================= 以下是html包applet時的code:
< applet
codebase = "."
code = "applettest.Applet1.class"
name = "TestApplet"
width = "400"
height = "300"
hspace = "0"
vspace = "0"
align = "middle"
>
==============================================================
|
superhank
一般會員 發表:8 回覆:24 積分:6 註冊:2003-06-30 發送簡訊給我 |
|
neoart
版主 發表:22 回覆:582 積分:425 註冊:2003-05-09 發送簡訊給我 |
|
neoart
版主 發表:22 回覆:582 積分:425 註冊:2003-05-09 發送簡訊給我 |
|
superhank
一般會員 發表:8 回覆:24 積分:6 註冊:2003-06-30 發送簡訊給我 |
|
neoart
版主 發表:22 回覆:582 積分:425 註冊:2003-05-09 發送簡訊給我 |
|
superhank
一般會員 發表:8 回覆:24 積分:6 註冊:2003-06-30 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |