Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java IDE  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 java Web浏览器
chenmin200396





发贴: 1
积分: 0
于 2006-07-30 22:02 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
package HtmlBrowser;

import java.io.IOException;
import java.net.URL;
import javax.swing.*;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;

public class HtmlBrowser extends JFrame {
  JPanel contentPane;                  // 包含整个框架的容器
  BorderLayout borderLayoutAll = new BorderLayout();
  JLabel jLabelPrompt = new JLabel();          // 状态提示框
  JPanel jPanelMain = new JPanel();          // 包含URL编辑框和JEditorPane的容器
  BorderLayout borderLayoutMain = new BorderLayout();
  JTextField textFieldURL = new JTextField();      // URL输入框
  JEditorPane jEditorPane = new JEditorPane();    // 显示网页内容的容器

  // 构造函数
  public HtmlBrowser() {
  try {
    jbInit(); // 初始化并显示界面
  }
  catch(Exception e) {
    e.printStackTrace();
  }
  }

  // 初始化并显示界面
  private void jbInit() throws Exception {
   contentPane = (JPanel)getContentPane();
  contentPane.setLayout(borderLayoutAll);

   jPanelMain.setLayout(borderLayoutMain);
   jLabelPrompt.setText("请输入完整的URL");
  
   textFieldURL.setText("");
   textFieldURL.addActionListener(new java.awt.event.ActionListener() {
     public void actionPerformed(ActionEvent e) {
     textFieldURL_actionPerformedEnvelope;
     }
   });
  
   jEditorPane.setEditable(false);
   jEditorPane.addHyperlinkListener(new javax.swing.event.HyperlinkListener() {
     public void hyperlinkUpdate(HyperlinkEvent e) {
     jEditorPane_hyperlinkUpdateEnvelope;
     }
   });
  
   JScrollPane scrollPane = new JScrollPane();
   scrollPane.getViewport().add(jEditorPane);
  
   jPanelMain.add(textFieldURL, "North");
   jPanelMain.add(scrollPane, "Center");
   contentPane.add(jLabelPrompt, "North");
   contentPane.add(jPanelMain, "Center");
  
   enableEvents(AWTEvent.WINDOW_EVENT_MASK);
   this.setSize(new Dimension(800, 600));
   this.setTitle("网页浏览器");
   this.setVisible(true);
  }

  // 响应回车
  void textFieldURL_actionPerformed(ActionEvent e) {
   try {
      jEditorPane.setPage(textFieldURL.getText()); // 显示所给的URL内容
   }
   catch(IOException ex) {
      JOptionPane msg = new JOptionPane(); // 提示对话框
      JOptionPane.showMessageDialog(this, "不正确的URL地址:"+textFieldURL.getText(), "不正确的输入!", 0);
   }
  }

  // 响应打开超级链接的消息
  void jEditorPane_hyperlinkUpdate(HyperlinkEvent e) {
  if(e.getEventType() == javax.swing.event.HyperlinkEvent.EventType.ACTIVATED) {
    try {
    URL url = e.getURL(); // 从消息中得到URL地址
    jEditorPane.setPage(url); // 显示该URL页面的内容
    textFieldURL.setText(url.toString()); // 显示URL地址
    }
    catch(IOException io){
    JOptionPane msg = new JOptionPane();
    JOptionPane.showMessageDialog(this, "无法打开链接!", "输入错误!", 0);
    }
  }
  }

  // 关闭窗口
  protected void processWindowEvent(WindowEvent e) {
  super.processWindowEventEnvelope;
  if (e.getID() == WindowEvent.WINDOW_CLOSING) {
     System.exit(0);
  }
  }
  
  // 主函数
  public static void main(String[] args) {
  new HtmlBrowser();
  }
}



作者 Tip for Proxy used [Re:chenmin200396]
铁针





发贴: 90
积分: 1
于 2006-08-01 11:11 user profilesend a private message to usersend email to 铁针search all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
If a proxy is used for http all requests in your company or local network, please set JVM parameters to use proxy before running this programme.

-Dhttp.proxyHost=192.168.161.30 -Dhttp.proxyPort=8080





flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923