用Java做一个WWW浏览器现在用JB做出了WWW浏览器的界面,
具体的功能模块还进行当中,
比如如何在地址栏中输入网址就可以浏览网页等等....
哈哈,这是我的毕业设计,不知这里有谁用Java做过WWW浏览器的呢?
能给点指点的吗?
谢谢.

解决方案 »

  1.   

    // HTMLExample.java
    //
    import javax.swing.*;
    import javax.swing.event.*;
    import java.io.*;
    public class HTMLExample {
    public static void main(String[] args) {
    JEditorPane pane = null;
    try {
    pane = new JEditorPane(args[0]);
    }
    catch (IOException ex) {
    ex.printStackTrace(System.err);
    System.exit(1);
    }
    pane.setEditable(false);
    // Add a hyperlink listener
    final JEditorPane finalPane = pane;
    pane.addHyperlinkListener(new HyperlinkListener() {
    public void hyperlinkUpdate(HyperlinkEvent ev) {
    try {
    if (ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
    finalPane.setPage(ev.getURL());
    } catch (IOException ex) { ex.printStackTrace(System.err); }
    }
    });
    JFrame frame = new JFrame();
    frame.addWindowListener(new BasicWindowMonitor());
    frame.setContentPane(new JScrollPane(pane));
    frame.setSize(350,400);
    frame.setVisible(true);
    }
    }
    其实做一个浏览器当毕业设计简直是太简单了,我这个例子很简单,但是如果你想做的复杂一点也不难啊,稍微看看书就行。
      

  2.   

    你去书店 看 java how to program 第5版 虽然书翻译的不好,但是上面在网络那张就有一个操作url的东西(应该时例子)
      

  3.   

    你可以看看hotjava,一个很老的java浏览器
      

  4.   

    hotjava下载下来
    解压缩
    有源代码可以看的
      

  5.   

    apache commons httpclient 包里有你要的东西,关于http的大量工具,足够你做十个浏览器。
      

  6.   

    《java网络编程》中有一个完整的实例
      

  7.   

    // DummyBrowser.javaimport javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;
    import java.util.Stack;/**
     * 
     * "DummyBrowser" is a very simple minimalist web browser, written in Java.
     * It uses the JEditPane swing component to render HTML pages,
     * and to follow links to other pages. Note that JEditPane can only
     * render <b>some</b> HTML, so that pages with HTML content it can't
     * handle will either not be correctly rendered, or will cause errors.
     * 
     * <p>
     * This program is heavily based on the Java demonstration Browser class,
     * written by <a href="http://www.apl.jhu.edu/~hall/java/">Marty Hall
     * - www.apl.jhu.edu/~hall/java</a> in 1998.
     * It has been modified by Lawrie Brown to add a few more features,
     * to suit its use to test web server access in isolated, test
     * computer networking and cisco lab classes.
     *
     * @author Lawrie Brown
     * @version 31 Mar 2005
     * @see <a href="http://www.unsw.adfa.edu.au/~lpb/">Lawrie Brown's ADFA home</a>
     * @see <a href="http://www.apl.jhu.edu/~hall/java/">Marty Hall - demo java Browser</a>
     */ /**
      * Modify:
      *     2005-4-17 by HITXU.
      */public class DummyBrowser extends JFrame implements HyperlinkListener, 
                                                   ActionListener {  private JButton homeButton, backButton, quitButton;
      private JTextField urlField;
      private JEditorPane htmlPane;
      private String startURL = null;
      private Stack history;  /**
       * main program routine which creates a new instance of DummyBrowser,
       * displaying either the default home page describing this program,
       * or the file named on the command-line.
       */
      public static void main(String[] args) {
        if (args.length == 0)
          new DummyBrowser("http://www.csdn.net");
        else
          new DummyBrowser(args[0]);
      }  /**
       *  construct a new DummyBrowser instance, displaying the local file
       *  whose name is supplied to the constructor.
       *
       * @param file the local file to display
       */
      public DummyBrowser(String file) {
        super("Dummy Browser");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); history = new Stack();
        // setup initial file URL and history stack
    if(file != null)
    {
          startURL = this.getClass().getResource(file).toExternalForm();    
          history.push(startURL);
    }
        // build the GUI components for DummyBrowser
        JPanel topPanel = new JPanel();
        topPanel.setBackground(Color.lightGray);
        homeButton = new JButton("Home");
        homeButton.addActionListener(this);
        backButton = new JButton("Back");
        backButton.addActionListener(this);
        quitButton = new JButton("Quit");
        quitButton.addActionListener(this);
        JLabel urlLabel = new JLabel("URL:");
        urlField = new JTextField(30);
        urlField.setText(startURL);
        urlField.addActionListener(this);
        topPanel.add(homeButton);
        topPanel.add(urlLabel);
        topPanel.add(urlField);
        topPanel.add(backButton);
        topPanel.add(quitButton);
        getContentPane().add(topPanel, BorderLayout.NORTH);    htmlPane = new JEditorPane();
        htmlPane.setEditable(false);
        htmlPane.addHyperlinkListener(this);
        try {
       if(startURL != null)
             htmlPane.setPage(startURL);
        } catch(IOException ioe) {
           warnUser("Error rendering initial HTML page " + startURL + ": " + ioe);
        }
        JScrollPane scrollPane = new JScrollPane(htmlPane);
        getContentPane().add(scrollPane, BorderLayout.CENTER);    Dimension screenSize = getToolkit().getScreenSize();
        int width = screenSize.width * 8 / 10;
        int height = screenSize.height * 8 / 10;
        setBounds(width/8, height/8, width, height);
        setVisible(true);
      }  public void actionPerformed(ActionEvent event) {
        String url = startURL;
        Object source = event.getSource();
        if (source == urlField) {
          url = urlField.getText();
        } else if (source == backButton) {
          if (!history.empty()) url = (String)history.pop(); // pop current page
          if (!history.empty()) url = (String)history.pop(); // pop previous page
        } else if (source == quitButton) {
          System.exit(0);
        }
        // assume Home button pressed if none of above    try {
          htmlPane.setPage(new URL(url));
          urlField.setText(url);
          history.push(url);
        } catch(IOException ioe) {
          warnUser("Can't follow link to " + url + ": " + ioe);
        }
      }  public void hyperlinkUpdate(HyperlinkEvent event) {
        if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
          try {
            htmlPane.setPage(event.getURL());
            urlField.setText(event.getURL().toExternalForm());
            history.push(event.getURL().toExternalForm());
          } catch(IOException ioe) {
            warnUser("Can't follow link to " 
                     + event.getURL().toExternalForm() + ": " + ioe);
          }
        }
      }  private void warnUser(String message) {
        JOptionPane.showMessageDialog(this, message, "Error", 
                                      JOptionPane.ERROR_MESSAGE);
      }  public void windowClosing(WindowEvent event) {
        System.exit(0);
      }}
      

  8.   

    To: 回复人: HitXU(一天不学习,赶不上刘少奇) ( ) 信誉:100  2005-04-17 13:30:00  得分: 0  
    C:\>java DummyBrowser www.163.com
    Exception in thread "main" java.lang.NullPointerException
            at DummyBrowser.<init>(DummyBrowser.java:73)
            at DummyBrowser.main(DummyBrowser.java:56)
    C:\>java DummyBrowser
    Exception in thread "main" java.lang.NullPointerException
            at DummyBrowser.<init>(DummyBrowser.java:73)
            at DummyBrowser.main(DummyBrowser.java:54)
      

  9.   

    看一下一个很好的java html控件
    比swing的好多了,还支持javascript
    http://www.icesoft.com/还有,这个是调用mozilla的
    http://jrex.mozdev.org/swt的browser也不错,win下调用ie,linux下调用mozilla,mac下调用safari
      

  10.   

    还有你要myie的源码吗?要的留个email
      

  11.   

    MYIE的源码还是现在的MAXTHON?是什么的?C++?还是DELPHI?
      

  12.   

    myie的,不是maxthon(myie2),C++,3.2版吧据我在maxthon论坛上潜水所知,目前国内几乎所有的tabbed browser,象maxthon,green browser等在开始时都是基于myie的源码!
      

  13.   

    要是有哪个WWW浏览器的源码,可以发给我,
    不过,只要Java的,好像那些WWW浏览器都是用VC做的吧?
      

  14.   

    重新贴一下,不要初始页面了。// DummyBrowser.javaimport javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;
    import java.util.Stack;/**
     * 
     * "DummyBrowser" is a very simple minimalist web browser, written in Java.
     * It uses the JEditPane swing component to render HTML pages,
     * and to follow links to other pages. Note that JEditPane can only
     * render <b>some</b> HTML, so that pages with HTML content it can't
     * handle will either not be correctly rendered, or will cause errors.
     * 
     * <p>
     * This program is heavily based on the Java demonstration Browser class,
     * written by <a href="http://www.apl.jhu.edu/~hall/java/">Marty Hall
     * - www.apl.jhu.edu/~hall/java</a> in 1998.
     * It has been modified by Lawrie Brown to add a few more features,
     * to suit its use to test web server access in isolated, test
     * computer networking and cisco lab classes.
     *
     * @author Lawrie Brown
     * @version 31 Mar 2005
     * @see <a href="http://www.unsw.adfa.edu.au/~lpb/">Lawrie Brown's ADFA home</a>
     * @see <a href="http://www.apl.jhu.edu/~hall/java/">Marty Hall - demo java Browser</a>
     */ /**
      * Modified:
      *     2005-4-18 by HITXU.
      */public class DummyBrowser extends JFrame implements HyperlinkListener, 
                                                   ActionListener {  private JButton homeButton, backButton, quitButton;
      private JTextField urlField;
      private JEditorPane htmlPane;
      private String startURL = null;
      private Stack history;  /**
       * main program routine which creates a new instance of DummyBrowser,
       * displaying either the default home page describing this program,
       * or the file named on the command-line.
       */
      public static void main(String[] args) {
        if (args.length == 0)
          new DummyBrowser(null);
        else
          new DummyBrowser(args[0]);
      }  /**
       *  construct a new DummyBrowser instance, displaying the local file
       *  whose name is supplied to the constructor.
       *
       * @param file the local file to display
       */
      public DummyBrowser(String file) {
        super("Dummy Browser");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); history = new Stack();
        // setup initial file URL and history stack
    if(file != null)
    {
          startURL = this.getClass().getResource(file).toExternalForm();    
          history.push(startURL);
    }
        // build the GUI components for DummyBrowser
        JPanel topPanel = new JPanel();
        topPanel.setBackground(Color.lightGray);
        homeButton = new JButton("Home");
        homeButton.addActionListener(this);
        backButton = new JButton("Back");
        backButton.addActionListener(this);
        quitButton = new JButton("Quit");
        quitButton.addActionListener(this);
        JLabel urlLabel = new JLabel("URL:");
        urlField = new JTextField(30);
        urlField.setText(startURL);
        urlField.addActionListener(this);
        topPanel.add(homeButton);
        topPanel.add(urlLabel);
        topPanel.add(urlField);
        topPanel.add(backButton);
        topPanel.add(quitButton);
        getContentPane().add(topPanel, BorderLayout.NORTH);    htmlPane = new JEditorPane();
        htmlPane.setEditable(false);
        htmlPane.addHyperlinkListener(this);
        try {
       if(startURL != null)
             htmlPane.setPage(startURL);
        } catch(IOException ioe) {
           warnUser("Error rendering initial HTML page " + startURL + ": " + ioe);
        }
        JScrollPane scrollPane = new JScrollPane(htmlPane);
        getContentPane().add(scrollPane, BorderLayout.CENTER);    Dimension screenSize = getToolkit().getScreenSize();
        int width = screenSize.width * 8 / 10;
        int height = screenSize.height * 8 / 10;
        setBounds(width/8, height/8, width, height);
        setVisible(true);
      }  public void actionPerformed(ActionEvent event) {
        String url = startURL;
        Object source = event.getSource();
        if (source == urlField) {
          url = urlField.getText();
        } else if (source == backButton) {
          if (!history.empty()) url = (String)history.pop(); // pop current page
          if (!history.empty()) url = (String)history.pop(); // pop previous page
        } else if (source == quitButton) {
          System.exit(0);
        }
        // assume Home button pressed if none of above    try {
          htmlPane.setPage(new URL(url));
          urlField.setText(url);
          history.push(url);
        } catch(IOException ioe) {
          warnUser("Can't follow link to " + url + ": " + ioe);
        }
      }  public void hyperlinkUpdate(HyperlinkEvent event) {
        if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
          try {
            htmlPane.setPage(event.getURL());
            urlField.setText(event.getURL().toExternalForm());
            history.push(event.getURL().toExternalForm());
          } catch(IOException ioe) {
            warnUser("Can't follow link to " 
                     + event.getURL().toExternalForm() + ": " + ioe);
          }
        }
      }  private void warnUser(String message) {
        JOptionPane.showMessageDialog(this, message, "Error", 
                                      JOptionPane.ERROR_MESSAGE);
      }  public void windowClosing(WindowEvent event) {
        System.exit(0);
      }}
      

  15.   

    http://www.ojava.net/read.php?tid=24&fpage=1
    浏览器源码.Java的
      

  16.   

    哪有那么简单?你们怎么会想象得那么简单呢?该不会是把IE的库拿来调用吧?浏览器要实现的功能很多啊,比如EXCEL、WORD的操作,动态图象,JAVASCRIPT的支持,这些哪个不需要你干上半年!我说得对不对?
      

  17.   

    现在我们所作只有调用别的browser控件,java的可以直接调用swing的JEditorPane,或我说的第三方html显示控件比swing的好多了,还支持javascript
    http://www.icesoft.com/还有,这个是调用mozilla的
    http://jrex.mozdev.org/swt的browser也不错,win下调用ie,linux下调用mozilla,mac下调用safari难道这里有牛人准备自己写一个html显示控件,不但要渲染页面,还要控制JAVASCRIPT?半年哪够?要是只要半年,mozilla还要那么多人,写那些年?
      

  18.   

    Mark 好贴,好资源,HOHOPS:如果什么都从头开始搞,从低层做起,那中国的计算机算是完了.
      

  19.   

    自己做支持javascript的浏览器?那可就真的不简单了,我很期待搂主的作品!
    swing的EditPane很差的,很多东西都不支持。
      

  20.   

    To wandanle(给命运点阳光它就灿烂,它一灿烂我就完蛋):    呵呵,任何一个东西想做专业了都很困难,我说的简单是指应付毕业设计,也刚从大学走出来没几天,很了解目前大学的情况,做一个应付毕业设计的浏览器还是很轻松的。如果多下点功夫做的好一点,说不定还能评个优秀呢。。^_^
      

  21.   

    回复人: parol2910(树上的青蛙) ( ) 信誉:100  2005-04-19 08:49:00  得分: 0  
    http://www.ojava.net/read.php?tid=24&fpage=1
    浏览器源码.Java的这个网页打不开啊???
      

  22.   

    还有,我是用JB做的,
    这与JDK有点不同的!
      

  23.   

    还有,我是用JB做的,
    这与JDK有点不同的!
    ??????
      

  24.   

    foxty(火狐) ( ) 信誉:100  2005-04-19 14:04:00  得分: 0  
     
       Mark 好贴,好资源,HOHOPS:如果什么都从头开始搞,从低层做起,那中国的计算机算是完了.
    =================================================================哈哈,恰恰相反,如果什么都用别人的,那中国的计算机才真正完了。你说说,现在中国的计算机业还剩下什么了?  
     
      

  25.   

    to wandanle(给命运点阳光它就灿烂,它一灿烂我就完蛋) :我们现在说的是楼主的毕设问题,不要什么都上升到国家高度,楼主一个人(好吧,就算是一个班),在一两个月内能从底层做起?
      

  26.   

    dyhml(VirusCamp):这我知道,我只是针对你的那句话--如果什么都从头开始搞,从低层做起,那中国的计算机算是完了--说的,毕竟是你先上升到国家的高度。
      

  27.   

    我现在做的这个简单的WWW浏览器,不能浏览图片和FLASH,高手能指点吗?
      

  28.   

    参考JAVA编程艺术第7章import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.text.html.*;// The Mini Web Browser.
    public class MiniBrowser extends JFrame
      implements HyperlinkListener
    {
      // These are the buttons for iterating through the page list.
      private JButton backButton, forwardButton;  // Page location text field.
      private JTextField locationTextField;  // Editor pane for displaying pages.
      private JEditorPane displayEditorPane;  // Browser's list of pages that have been visited.
      private ArrayList pageList = new ArrayList();  // Constructor for Mini Web Browser.
      public MiniBrowser()
      {
        // Set application title.
        super("Mini Browser");    // Set window size.
        setSize(640, 480);    // Handle closing events.
        addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            actionExit();
          }
        });    // Set up file menu.
        JMenuBar menuBar = new JMenuBar();
        JMenu fileMenu = new JMenu("File");
        fileMenu.setMnemonic(KeyEvent.VK_F);
        JMenuItem fileExitMenuItem = new JMenuItem("Exit",
          KeyEvent.VK_X);
        fileExitMenuItem.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            actionExit();
          }
        });
        fileMenu.add(fileExitMenuItem);
        menuBar.add(fileMenu);
        setJMenuBar(menuBar);    // Set up button panel.
        JPanel buttonPanel = new JPanel();
        backButton = new JButton("< Back");
        backButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            actionBack();
          }
        });
        backButton.setEnabled(false);
        buttonPanel.add(backButton);
        forwardButton = new JButton("Forward >");
        forwardButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            actionForward();
          }
        });
        forwardButton.setEnabled(false);
        buttonPanel.add(forwardButton);
        locationTextField = new JTextField(35);
        locationTextField.addKeyListener(new KeyAdapter() {
          public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
              actionGo();
            }
          }
        });
        buttonPanel.add(locationTextField);
        JButton goButton = new JButton("GO");
        goButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            actionGo();
          }
        });
        buttonPanel.add(goButton);    // Set up page display.
        displayEditorPane = new JEditorPane();
        displayEditorPane.setContentType("text/html");
        displayEditorPane.setEditable(false);
        displayEditorPane.addHyperlinkListener(this);    getContentPane().setLayout(new BorderLayout());
        getContentPane().add(buttonPanel, BorderLayout.NORTH);
        getContentPane().add(new JScrollPane(displayEditorPane),
          BorderLayout.CENTER);
      }  // Exit this program.
      private void actionExit() {
        System.exit(0);
      }  // Go back to the page viewed before the current page.
      private void actionBack() {
        URL currentUrl = displayEditorPane.getPage();
        int pageIndex = pageList.indexOf(currentUrl.toString());
        try {
          showPage(
            new URL((String) pageList.get(pageIndex - 1)), false);
        }
        catch (Exception e) {}
      }  // Go forward to the page viewed after the current page.
      private void actionForward() {
        URL currentUrl = displayEditorPane.getPage();
        int pageIndex = pageList.indexOf(currentUrl.toString());
        try {
          showPage(
            new URL((String) pageList.get(pageIndex + 1)), false);
        }
        catch (Exception e) {}
      }  // Load and show the page specified in the location text field.
      private void actionGo() {
        URL verifiedUrl = verifyUrl(locationTextField.getText());
        if (verifiedUrl != null) {
          showPage(verifiedUrl, true);
        } else {
          showError("Invalid URL");
        }
      }  // Show dialog box with error message.
      private void showError(String errorMessage) {
        JOptionPane.showMessageDialog(this, errorMessage,
          "Error", JOptionPane.ERROR_MESSAGE);
      }  // Verify URL format.
      private URL verifyUrl(String url) {
        // Only allow HTTP URLs.
        if (!url.toLowerCase().startsWith("http://"))
          return null;    // Verify format of URL.
        URL verifiedUrl = null;
        try {
          verifiedUrl = new URL(url);
        } catch (Exception e) {
          return null;
        }    return verifiedUrl;
      }  /* Show the specified page and add it to
         the page list if specified. */
      private void showPage(URL pageUrl, boolean addToList)
      {
        // Show hour glass cursor while crawling is under way.
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));    try {
          // Get URL of page currently being displayed.
          URL currentUrl = displayEditorPane.getPage();      // Load and display specified page.
          displayEditorPane.setPage(pageUrl);      // Get URL of new page being displayed.
          URL newUrl = displayEditorPane.getPage();      // Add page to list if specified.
          if (addToList) {
            int listSize = pageList.size();
            if (listSize > 0) {
              int pageIndex =
                pageList.indexOf(currentUrl.toString());
              if (pageIndex < listSize - 1) {
                for (int i = listSize - 1; i > pageIndex; i--) {
                  pageList.remove(i);
                }
              }
            }
            pageList.add(newUrl.toString());
          }      // Update location text field with URL of current page.
          locationTextField.setText(newUrl.toString());      // Update buttons based on the page being displayed.
          updateButtons();
        }
        catch (Exception e)
        {
          // Show error messsage.
          showError("Unable to load page");
        }
        finally
        {
          // Return to default cursor.
          setCursor(Cursor.getDefaultCursor());
        }
      }  /* Update back and forward buttons based on
         the page being displayed. */
      private void updateButtons() {
        if (pageList.size() < 2) {
          backButton.setEnabled(false);
          forwardButton.setEnabled(false);
        } else {
          URL currentUrl = displayEditorPane.getPage();
          int pageIndex = pageList.indexOf(currentUrl.toString());
          backButton.setEnabled(pageIndex > 0);
          forwardButton.setEnabled(
            pageIndex < (pageList.size() - 1));
        }
      }  // Handle hyperlink's being clicked.
      public void hyperlinkUpdate(HyperlinkEvent event) {
        HyperlinkEvent.EventType eventType = event.getEventType();
        if (eventType == HyperlinkEvent.EventType.ACTIVATED) {
          if (event instanceof HTMLFrameHyperlinkEvent) {
            HTMLFrameHyperlinkEvent linkEvent =
              (HTMLFrameHyperlinkEvent) event;
            HTMLDocument document =
              (HTMLDocument) displayEditorPane.getDocument();
            document.processHTMLFrameHyperlinkEvent(linkEvent);
          } else {
              showPage(event.getURL(), true);
          }
        }
      }  // Run the Mini Browser.
      public static void main(String[] args) {
        MiniBrowser browser = new MiniBrowser();
        browser.show();
      }
    }
      

  29.   

    回复人: like_java(爱Java同C++) ( ) 信誉:100 :我现在做的这个简单的WWW浏览器,不能浏览图片和FLASH,高手能指点吗?
    ---------------------------我的分割线  盗版必究-----------------------------swing的JEditPane功能很弱的,不会支持FLASH,但图片是支持的.要不就用第三方的控件,要不就自己写?还是都算了吧,就这样了.
      

  30.   

    为什么做出一个与MYIE2差不多都这么难呢,现在浏览网页质量好差啊,
      

  31.   

    《java编程艺术》书上好像有一个这样的例子,不过还有好多的功能要自己添加就是了!
      

  32.   

    swing的JEditPane功能很弱的,浏览网页质量就是差
      

  33.   

    hotjava 浏览器可以支持很多格式,是不是程序代码没到位呢?