当前位置: 技术问答>java相关
如果让HTML显示在Applet里并打印出来?
来源: 互联网 发布时间:2015-11-21
本文导语: 如果让HTML显示在Applet里并打印出来? | import java.awt.*; import java.sql.*; import java.net.*; import javax.swing.*; import java.util.*; import javax.swing.event.*; import javax.swing.tree.*; class HTMLFrame extends JFrame { ...
如果让HTML显示在Applet里并打印出来?
|
import java.awt.*;
import java.sql.*;
import java.net.*;
import javax.swing.*;
import java.util.*;
import javax.swing.event.*;
import javax.swing.tree.*;
class HTMLFrame extends JFrame {
JSplitPane jSplitPane1 = new JSplitPane();
CardLayout cardLayout1 = new CardLayout();
JScrollPane jScrollPane1 = new JScrollPane();
JScrollPane jScrollPane2 = new JScrollPane();
JEditorPane content = new JEditorPane();
JTree jTree_help = new JTree();
ShellFrame shell_frame;
DBConnection conn;
Vector vparent_node = new Vector();
Vector vchild_node = new Vector();
String install_directory = "";
int init_flag = 0;
HTMLFrame(ShellFrame new_frame) {
shell_frame = new_frame;
conn = shell_frame.getConnection();
install_directory = shell_frame.install_directory;
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(cardLayout1);
content.setBorder(BorderFactory.createLoweredBevelBorder());
content.setEditable(false);
content.addHyperlinkListener(new HyperlinkListener(){
public void hyperlinkUpdate(HyperlinkEvent event){
setURL(event.getURL());
}
});
fill_jTree();
this.getContentPane().add(jSplitPane1, "jSplitPane1");
jSplitPane1.add(jScrollPane1, JSplitPane.LEFT);
jScrollPane1.getViewport().add(jTree_help, null);
jSplitPane1.add(jScrollPane2, JSplitPane.RIGHT);
jScrollPane2.getViewport().add(content, null);
jSplitPane1.setDividerLocation(200);
jTree_help.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
jTree_help_valueChanged(e);
}
});
Dimension screen_size = this.getToolkit().getScreenSize();
setLocation (0,0);
setSize(screen_size.width, screen_size.height-26);
this.setIconImage(Toolkit.getDefaultToolkit().createImage(shell_frame.str_init_directory.substring(6)+"/images/图标.jpg"));
}
void fill_jTree(){
if(init_flag>=1)
return;
try{
HTreeNode root = new HTreeNode("帮助");
root.set_address("/help/帮助.htm");
//构造子结点
jTree_help = new JTree(root);
} catch (Exception ex) {
ex.printStackTrace();
}
}
void jTree_help_valueChanged(TreeSelectionEvent e) {
TreePath SelectedTreePath = e.getNewLeadSelectionPath();
HTreeNode SelectedNode;
if (SelectedTreePath == null) {
SelectedNode = null;
return;
}
SelectedNode = (HTreeNode)SelectedTreePath.getLastPathComponent();
System.out.println(SelectedNode.get_address());
try{
URL newURL = new URL(shell_frame.str_init_directory+SelectedNode.get_address());
setURL(newURL);
} catch (Exception ex) {
System.out.println("this is exception!");
}
}
void setURL(URL newURL){
try{
content.setPage(newURL);
} catch (Exception ex) {
ex.printStackTrace();
}
}
void setContent(String directory){
try{
URL url = new URL(shell_frame.str_init_directory+directory);
setURL(url);
} catch (Exception ex) {
ex.printStackTrace();
}
}
class HTreeNode extends DefaultMutableTreeNode{
String help_address = "";
int tree_id = 0;
HTreeNode(Object userObject) {
super(userObject);
}
void set_address(String new_help_address){
help_address = new_help_address;
}
String get_address(){
return help_address;
}
void set_tree_id(int new_tree_id){
tree_id = new_tree_id;
}
int get_tree_id(){
return tree_id;
}
}
}
import java.sql.*;
import java.net.*;
import javax.swing.*;
import java.util.*;
import javax.swing.event.*;
import javax.swing.tree.*;
class HTMLFrame extends JFrame {
JSplitPane jSplitPane1 = new JSplitPane();
CardLayout cardLayout1 = new CardLayout();
JScrollPane jScrollPane1 = new JScrollPane();
JScrollPane jScrollPane2 = new JScrollPane();
JEditorPane content = new JEditorPane();
JTree jTree_help = new JTree();
ShellFrame shell_frame;
DBConnection conn;
Vector vparent_node = new Vector();
Vector vchild_node = new Vector();
String install_directory = "";
int init_flag = 0;
HTMLFrame(ShellFrame new_frame) {
shell_frame = new_frame;
conn = shell_frame.getConnection();
install_directory = shell_frame.install_directory;
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(cardLayout1);
content.setBorder(BorderFactory.createLoweredBevelBorder());
content.setEditable(false);
content.addHyperlinkListener(new HyperlinkListener(){
public void hyperlinkUpdate(HyperlinkEvent event){
setURL(event.getURL());
}
});
fill_jTree();
this.getContentPane().add(jSplitPane1, "jSplitPane1");
jSplitPane1.add(jScrollPane1, JSplitPane.LEFT);
jScrollPane1.getViewport().add(jTree_help, null);
jSplitPane1.add(jScrollPane2, JSplitPane.RIGHT);
jScrollPane2.getViewport().add(content, null);
jSplitPane1.setDividerLocation(200);
jTree_help.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
jTree_help_valueChanged(e);
}
});
Dimension screen_size = this.getToolkit().getScreenSize();
setLocation (0,0);
setSize(screen_size.width, screen_size.height-26);
this.setIconImage(Toolkit.getDefaultToolkit().createImage(shell_frame.str_init_directory.substring(6)+"/images/图标.jpg"));
}
void fill_jTree(){
if(init_flag>=1)
return;
try{
HTreeNode root = new HTreeNode("帮助");
root.set_address("/help/帮助.htm");
//构造子结点
jTree_help = new JTree(root);
} catch (Exception ex) {
ex.printStackTrace();
}
}
void jTree_help_valueChanged(TreeSelectionEvent e) {
TreePath SelectedTreePath = e.getNewLeadSelectionPath();
HTreeNode SelectedNode;
if (SelectedTreePath == null) {
SelectedNode = null;
return;
}
SelectedNode = (HTreeNode)SelectedTreePath.getLastPathComponent();
System.out.println(SelectedNode.get_address());
try{
URL newURL = new URL(shell_frame.str_init_directory+SelectedNode.get_address());
setURL(newURL);
} catch (Exception ex) {
System.out.println("this is exception!");
}
}
void setURL(URL newURL){
try{
content.setPage(newURL);
} catch (Exception ex) {
ex.printStackTrace();
}
}
void setContent(String directory){
try{
URL url = new URL(shell_frame.str_init_directory+directory);
setURL(url);
} catch (Exception ex) {
ex.printStackTrace();
}
}
class HTreeNode extends DefaultMutableTreeNode{
String help_address = "";
int tree_id = 0;
HTreeNode(Object userObject) {
super(userObject);
}
void set_address(String new_help_address){
help_address = new_help_address;
}
String get_address(){
return help_address;
}
void set_tree_id(int new_tree_id){
tree_id = new_tree_id;
}
int get_tree_id(){
return tree_id;
}
}
}