5 Replies Latest reply: Dec 7, 2007 10:50 AM by 807603 RSS

    How to display HTML file???

    807603
      Hi�.
      I�m working on a project in Network Programming course� The project is about developing a client/server search engine where the client sends a keyword to the server, and the server searches that keyword on the net and returns back the result to the client�.
      In fact, I�m done with the project except one more tiny thing�
      After the client receives the result, I�m saving that result in its workspace as �Result.html��
      My question is that,
      how could I display that html file without the client opens it from its workspace�

      Please, if you don�t mind to kindly help me� And every reply will be highly appreciated�.
        • 1. Re: How to display HTML file???
          807603
          I'm not sure what you mean by "without the client opens it from its workspace", but... here are two ways.

          1) Using Desktop...
          import java.awt.Desktop;
          
          //other code...
          
          public void displayHTMLFile(String loc) {
              URI uri = new URI(loc);
              Desktop.getDesktop().browse(uri);
          }
          EDIT:

          2) Using JEditorPane
          import javax.swing.*;
          
          public class showHTMLFile extends JFrame {
              public showHTMLFile(String url) {
                   super("Displaying the HTML File...");
                   JEditorPane jep = new JEditorPane(url);
                   getContentPane().add(jep);
                   setSize(500, 500); //put some numbers
                   setVisible(true);
              }
          }
          Edited by: Student_Coder on Dec 1, 2007 9:33 AM
          • 2. Re: How to display HTML file???
            807603
            <<<<<<<<<<<<<<<Thanks>>>>>>>>>>>>>>

            I would like to thank you very much for helping me :) �.
            I tried the first solution you gave me and it works fine�

            Thanks, Student_Coder, for your kind assistance and cooperation�.
            My 'Mom' would like to thank you as well...

            God bless you

            Edited by: Calyptra on Dec 1, 2007 4:44 PM
            • 3. Re: How to display HTML file???
              807603
              If you don't mind to kindly tell me how could I display the html file saved in the work space of the client as ("Result.html") using GUIs.

              I tried to use methods such as JEditorPane and JScrollPane, but both require the use of URL...

              I thought about converting URI into URL but it doesn't work..

              ex..

              JTextPane tp = new JTextPane();
              JScrollPane js = new JScrollPane();          
              js.getViewport().add(tp);
              JFrame jf = new JFrame();
              jf.getContentPane().add(js);
              jf.pack();
              jf.setSize(400,500);
              jf.setVisible(true);

              tp.setPage("Result.html");


              Please I need your help....
              Thanks
              • 4. Re: How to display HTML file???
                807603
                More questions....
                • 5. Re: How to display HTML file???
                  807603
                  Thanks very much...
                  I solved the problem by my self....