import java.awt.*;
import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
public class ShowHtml {
JFrame frame;
JEditorPane editorPane;
File file;
String str;
public ShowHtml() {
file = new File("index.html");
str = file.getAbsolutePath();
str = "file:" + str;
frame = new JFrame("JEditPane");
try {
editorPane = new JEditorPane();
editorPane.setEditable(false);
editorPane.setContentType("text/html");
editorPane.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
try {
editorPane.setPage(e.getURL());
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
// editorPane.setPage(str);
editorPane.setPage("http://www.baidu.com");
} catch (IOException ex) {
System.out.println("加载不成功!");
System.out.println("IOException: " + ex);
}
frame.getContentPane().add(new JScrollPane(editorPane),
BorderLayout.CENTER);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setSize(100, 260);
frame.setVisible(true);
}
public static void main(String[] args) {
ShowHtml ShowHtml1 = new ShowHtml();
}
}
import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
public class ShowHtml {
JFrame frame;
JEditorPane editorPane;
File file;
String str;
public ShowHtml() {
file = new File("index.html");
str = file.getAbsolutePath();
str = "file:" + str;
frame = new JFrame("JEditPane");
try {
editorPane = new JEditorPane();
editorPane.setEditable(false);
editorPane.setContentType("text/html");
editorPane.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
try {
editorPane.setPage(e.getURL());
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
// editorPane.setPage(str);
editorPane.setPage("http://www.baidu.com");
} catch (IOException ex) {
System.out.println("加载不成功!");
System.out.println("IOException: " + ex);
}
frame.getContentPane().add(new JScrollPane(editorPane),
BorderLayout.CENTER);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setSize(100, 260);
frame.setVisible(true);
}
public static void main(String[] args) {
ShowHtml ShowHtml1 = new ShowHtml();
}
}