62,621
社区成员
发帖
与我相关
我的任务
分享
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.IOException;
public class Test extends JFrame {
private JEditorPane editorPane = new JEditorPane();
public Test() {
Container contentPane = getContentPane();
String url = "http://www.baidu.com";
try {
editorPane.setPage(url);
} catch (IOException ex) {
ex.printStackTrace();
}
contentPane.add(new JScrollPane(editorPane), BorderLayout.CENTER);
editorPane.setEditable(false);
editorPane.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
try {
editorPane.setPage(e.getURL());
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
}
public static void main(String args[]) {
GJApp.launch(new Test(), "JEditorPane", 300, 300, 450, 300);
}
}
class GJApp extends WindowAdapter {
static private JPanel statusArea = new JPanel();
static private JLabel status = new JLabel(" ");
static private ResourceBundle resources;
public static void launch(final JFrame f, String title, final int x,
final int y, final int w, int h) {
launch(f, title, x, y, w, h, null);
}
public static void launch(final JFrame f, String title, final int x,
final int y, final int w, int h, String propertiesFilename) {
f.setTitle(title);
f.setBounds(x, y, w, h);
f.setVisible(true);
statusArea.setBorder(BorderFactory.createEtchedBorder());
statusArea.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
statusArea.add(status);
status.setHorizontalAlignment(JLabel.LEFT);
f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
if (propertiesFilename != null) {
resources = ResourceBundle.getBundle(propertiesFilename, Locale
.getDefault());
}
f.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
System.exit(0);
}
});
}
static public JPanel getStatusArea() {
return statusArea;
}
static public void showStatus(String s) {
status.setText(s);
}
static Object getResource(String key) {
if (resources != null) {
return resources.getString(key);
}
return null;
}
}
package demo;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JFrame;
import org.jdesktop.jdic.browser.WebBrowser;
/**
*
* @author YBBPS
*/
public class Mytest {
public static void main(String[] args) throws MalformedURLException {
WebBrowser wb;
wb = new WebBrowser();
wb.setURL(new URL("http://www.renren.com"));
JFrame frame = new JFrame("MyTest");
frame.getContentPane().add(wb);
frame.setSize(800, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}