当前位置: 技术问答>java相关
Applet为什么能在JBuiler5中调试,而不能在浏览器中显示
来源: 互联网 发布时间:2015-02-23
本文导语: 原代码如下: package treeexample; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; import java.applet.*; public class Tree...
原代码如下:
package treeexample;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import java.applet.*;
public class TreeExample extends Applet {
static JFrame myFrame;
JTextField tf;
JTree tree;
public TreeExample(){
setLayout(new BorderLayout());
tf= new JTextField();
tf.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
addTextFieldValue();
}
});
add(tf,"North");
DefaultMutableTreeNode rootNode = createNodes();
tree = new JTree(rootNode);
tree.setRootVisible(true);
JScrollPane pane = new JScrollPane();
pane.setViewportView(tree);
add(pane,"Center");
JButton remove = new JButton("Remove");
remove.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae2){
removeSelectedNode();
}
});
add(remove,"South");
}
public void removeSelectedNode(){
TreePath selectionPath = tree.getSelectionPath();
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)selectionPath.getLastPathComponent();
((DefaultTreeModel)tree.getModel()).removeNodeFromParent(selectedNode);
}
public void addTextFieldValue(){
DefaultMutableTreeNode newNode = new DefaultMutableTreeNode (tf.getText());
TreePath selectionPath = tree.getSelectionPath();
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)selectionPath.getLastPathComponent();
((DefaultTreeModel)tree.getModel()).insertNodeInto(newNode, selectedNode, selectedNode.getChildCount());
}
public DefaultMutableTreeNode createNodes(){
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode ("Java Stuff");
DefaultMutableTreeNode resources = new DefaultMutableTreeNode ("Resources");
DefaultMutableTreeNode tools = new DefaultMutableTreeNode ("Tools");
rootNode.add(resources);
rootNode.add(tools);
DefaultMutableTreeNode webSites =new DefaultMutableTreeNode ("Web Sites");
DefaultMutableTreeNode books = new DefaultMutableTreeNode ("Books");
resources.add(webSites);
resources.add(books);
DefaultMutableTreeNode magazines = new DefaultMutableTreeNode ("Magazines");
webSites.add(new DefaultMutableTreeNode ("JavaSoft"));
webSites.add(new DefaultMutableTreeNode ("Gamelan"));
webSites.add(magazines);
magazines.add(new DefaultMutableTreeNode ("Javology"));
magazines.add(new DefaultMutableTreeNode ("JavaWorld"));
books.add(new DefaultMutableTreeNode ("Special Edition Using Java 1.2"));
tools.add(new DefaultMutableTreeNode ("JBuilder"));
tools.add(new DefaultMutableTreeNode ("Visual J++"));
tools.add(new DefaultMutableTreeNode ("Visual Age for Java"));
tools.add(new DefaultMutableTreeNode ("Apptivity"));
return rootNode;
}
}
package treeexample;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import java.applet.*;
public class TreeExample extends Applet {
static JFrame myFrame;
JTextField tf;
JTree tree;
public TreeExample(){
setLayout(new BorderLayout());
tf= new JTextField();
tf.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
addTextFieldValue();
}
});
add(tf,"North");
DefaultMutableTreeNode rootNode = createNodes();
tree = new JTree(rootNode);
tree.setRootVisible(true);
JScrollPane pane = new JScrollPane();
pane.setViewportView(tree);
add(pane,"Center");
JButton remove = new JButton("Remove");
remove.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae2){
removeSelectedNode();
}
});
add(remove,"South");
}
public void removeSelectedNode(){
TreePath selectionPath = tree.getSelectionPath();
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)selectionPath.getLastPathComponent();
((DefaultTreeModel)tree.getModel()).removeNodeFromParent(selectedNode);
}
public void addTextFieldValue(){
DefaultMutableTreeNode newNode = new DefaultMutableTreeNode (tf.getText());
TreePath selectionPath = tree.getSelectionPath();
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)selectionPath.getLastPathComponent();
((DefaultTreeModel)tree.getModel()).insertNodeInto(newNode, selectedNode, selectedNode.getChildCount());
}
public DefaultMutableTreeNode createNodes(){
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode ("Java Stuff");
DefaultMutableTreeNode resources = new DefaultMutableTreeNode ("Resources");
DefaultMutableTreeNode tools = new DefaultMutableTreeNode ("Tools");
rootNode.add(resources);
rootNode.add(tools);
DefaultMutableTreeNode webSites =new DefaultMutableTreeNode ("Web Sites");
DefaultMutableTreeNode books = new DefaultMutableTreeNode ("Books");
resources.add(webSites);
resources.add(books);
DefaultMutableTreeNode magazines = new DefaultMutableTreeNode ("Magazines");
webSites.add(new DefaultMutableTreeNode ("JavaSoft"));
webSites.add(new DefaultMutableTreeNode ("Gamelan"));
webSites.add(magazines);
magazines.add(new DefaultMutableTreeNode ("Javology"));
magazines.add(new DefaultMutableTreeNode ("JavaWorld"));
books.add(new DefaultMutableTreeNode ("Special Edition Using Java 1.2"));
tools.add(new DefaultMutableTreeNode ("JBuilder"));
tools.add(new DefaultMutableTreeNode ("Visual J++"));
tools.add(new DefaultMutableTreeNode ("Visual Age for Java"));
tools.add(new DefaultMutableTreeNode ("Apptivity"));
return rootNode;
}
}
|
因为你用了swing,用jdk1.4吧
|
确实是 swing 的关系。
单独装一次jre1.3.1 (or jdk);
用 netscape, 全安装;
或保证只用到 awt (ie5.5 以下)。
ie6 开始总得另装 plug-ins 。
sun 赢了官司,输了市场。
单独装一次jre1.3.1 (or jdk);
用 netscape, 全安装;
或保证只用到 awt (ie5.5 以下)。
ie6 开始总得另装 plug-ins 。
sun 赢了官司,输了市场。