Writing a Java Web Browser

I'm trying to write a simple Java based browser. Can anyone please help me with this code. I can't get it to load the URL
please help
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
import javax.swing.event.*;
import java.lang.*;
import javax.swing.text.*;
public class Browser extends JPanel implements ActionListener {
     Browser() {
          JPanel p = new JPanel();
          p.setLayout(new BorderLayout(5,5));
          final JEditorPane jt = new JEditorPane();
          final JTextField input = new JTextField("http://java.sun.com");
          //make read only
          jt.setEditable(false);
          //follow links
          jt.addHyperlinkListener(new HyperlinkListener () {
               public void hyperlinkUpdate(
                    final HyperlinkEvent e) {
                         if (e.getEventType() ==
                              HyperlinkEvent.EventType.ACTIVATED) {
                                   SwingUtilities.invokeLater(new Runnable() {
                                        public void run() {
                                             //Save original
                                             Document doc = jt.getDocument();
                                             try {
                                                  URL url = e.getURL();
                                                  jt.setPage(url);
                                                  input.setText(url.toString());
                                             } catch (IOException io) {
                                                  JOptionPane.showMessageDialog(
                                                       Browser.this, "Can't follow link",
                                                       "Invalid Input",JOptionPane.ERROR_MESSAGE);
                                                  jt.setDocument(doc);
                         JScrollPane pane = new JScrollPane();
                         pane.setBorder(
                              BorderFactory.createLoweredBevelBorder());
                         pane.getViewport().add(jt);
                         p.add(pane, BorderLayout.CENTER);
                         input.addActionListener(new ActionListener() {
                              public void actionPerformed(ActionEvent e) {
                                   try {
                                        jt.setPage(input.getText());
                                   } catch (IOException ex) {
                                        JOptionPane.showMessageDialog(
                                             Browser.this,"Invalid URL","Invalid Input",JOptionPane.ERROR_MESSAGE);
                              p.add(input, BorderLayout.SOUTH);
                              JFrame f = new JFrame();
                              f.getContentPane().add(p);
                              //f.getContentPane().setSize(400,400);
                              f.setVisible(true);
                         public void actionPerformed(ActionEvent e) {}
                         public static void main(String[] args) {
                              Browser b = new Browser();
                              b.setSize(500,500);
                    }

i made a few changes and it works.
i have marked the changes.
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
import javax.swing.event.*;
import java.lang.*;
import javax.swing.text.*;
public class Browser extends JFrame implements ActionListener {     Browser() {
          JPanel p = new JPanel();
          p.setLayout(new BorderLayout(5,5));
          final JEditorPane jt = new JEditorPane();
          final JTextField input = new JTextField("http://java.sun.com");
          //make read only
          jt.setEditable(false);
          //follow links
          jt.addHyperlinkListener(new HyperlinkListener () {
                    public void hyperlinkUpdate(final HyperlinkEvent e) {
                         if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                              SwingUtilities.invokeLater(new Runnable() {
                                        public void run() {
                                             //Save original
                                             Document doc = jt.getDocument();
                                             try {
                                                  URL url = e.getURL();
                                                  jt.setPage(url);
                                                  input.setText(url.toString());
                                             catch (IOException io) {
                                                  JOptionPane.showMessageDialog
                                                       ( Browser.this, "Can't follow link",
                                                         "Invalid Input",JOptionPane.ERROR_MESSAGE);
                                                  jt.setDocument(doc);
          JScrollPane pane = new JScrollPane();
          pane.setBorder(BorderFactory.createLoweredBevelBorder());
          pane.getViewport().add(jt);
          p.add(pane, BorderLayout.CENTER);
          input.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                         try {
                              jt.setPage(input.getText());
                         } catch (IOException ex) {
                              JOptionPane.showMessageDialog
                                   ( Browser.this,"Invalid URL","Invalid Input",JOptionPane.ERROR_MESSAGE);
          p.add(input, BorderLayout.SOUTH);
          //JFrame f = new JFrame();          getContentPane().add(p);
          //f.getContentPane().setSize(400,400);
          setVisible(true);
          this.addWindowListener(new java.awt.event.WindowAdapter() {                    public void windowClosing(java.awt.event.WindowEvent e) {
                         System.exit(0);
     public void actionPerformed(ActionEvent e) {}
     public static void main(String[] args) {
          Browser b = new Browser();
          b.setSize(500,500);
}

Similar Messages

  • Java - web browser

    Hi,
    I have an applet that POSTs a request to a browser and then retrieves the servers response to check it was posted OK.
    What I now need to do is stream the response back to the web browser to show the page that the server has returned. My code below works in that it reads the server response and outputs it to the console.
    However I am confused as to how to hook back in to the browser ?
    Any help would be really appreciated !
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.net.*;
    public class TestApplet extends JApplet
            public void init()
              try
                   postResult("Hello server!");
              catch(Exception e)
                   e.printStackTrace();
         private void postResult(String message) throws MalformedURLException, IOException
                String aLine; // only if reading response
              URL                 url;
              URLConnection   urlConn;
              DataOutputStream    printout;
              BufferedReader     input;
              // URL of CGI-Bin script.
              url = new URL (getCodeBase().toString() + "test.php");
              urlConn = url.openConnection();
    // Let the run-time system (RTS) know what comms we want to make.
              urlConn.setDoInput (true);
              urlConn.setDoOutput (true);
              urlConn.setUseCaches (false);
              // Specify the content type.
              urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
              // Send POST output.
              printout = new DataOutputStream (urlConn.getOutputStream ());
              String content = "msg=" + URLEncoder.encode(message, "UTF-8");
              printout.writeBytes (content);
              printout.flush ();
              printout.close ();
              // Get response data. This is the bit that retrieves the page back from the server ...
              input = new BufferedReader(new InputStreamReader(urlConn.getInputStream ()));
              String str;
              while (null != ((str = input.readLine())))
                   System.out.println (str); //  <-- Need this to hook back in to browser...
             input.close ();
    }

    I got the impression, that applets are not the right thing for what you want to do. An applet can only output something in it's own (graphical) pane. If your data is HTML, this would mean to interpret and render the HTML on your own.
    I suggest to consider server side technologies (Servlets, PHP, CGI) which usually return plain HTML to the browser by default.

  • Java Web Browser Pleeease Help !!!

    I did a light web Browser with Java I want that my web browser supports the following Internet standards and protocols likes :
    HTTP 1.1 Protocol
    HTML 4
    Tables and Frames
    Persistent Cookies
    GIF and JPEG Media Formats
    AU Audio Format
    FTP and Gopher File Transfer Protocols
    SMTP and MIME E-mail Protocols
    SOCKS Protocol
    Java Archive (JAR) Format
    THANKs
    Pleeeeeeeeeeease Help me

    i do not wanna do web browser, that is my coswork,Still you need to give a bit more info.
    1) Be aware that data and view of the data are and should remain different things.
    The ArrayList can be used to save the Favourites. And the JList can be used to display them. Alternately, you could also use a tree of Favourite objects, with Favourite extending DefaultMutableTreeNode. This tree can then be displayed using JTree.
    http://java.sun.com/docs/books/tutorial/uiswing/components/index.htmlJust in case you need it.

  • Writing language at web browser

    Hi
    I have a Nokia e61i; and while on web pages where i have to enter text; i couldn't change the writing/input language! how i can do so? should i get out to to messages change the writing language from there every time? Shouldn't we be able to change it within the web browesr?

    Hi
    I have a Nokia e61i; and while on web pages where i have to enter text; i couldn't change the writing/input language! how i can do so? should i get out to to messages change the writing language from there every time? Shouldn't we be able to change it within the web browesr?

  • Problem with Java Web Browser

    Hi all,
    I use JEditorPane to display simple HTML files:
    String url = "http://www.fnac.com";
    JEditorPane editorPane = new JEditorPane(url);
    editorPane.setEditable(false);
    But for page www.fnac.com, the browser can not dipslay all object in Web page event I put JEditorPane in a JScrollPane.
    Someone can help me ?
    Thanks.

    I'm afraid I do not understand your question...
    "browser can not dipslay all object"- What object?
    "Web page event"- What event?

  • Problem with Java Web Browser -JEditorPane

    Hi,
    I use JEditorPane to display simple HTML files:
    String url = "http://www.fnac.com";
    JEditorPane editorPane = new JEditorPane(url);
    editorPane.setEditable(false);
    But for page www.fnac.com, the browser can not dipslay all objects of Web page (Images, Texts...) although I put JEditorPane in a JScrollPane.
    Someone tell me solution for this problem ? Thanks.

    PLEASE HELP ! Thanks.

  • Help need in Web Browser Project

    Hai,
    I am doing a java Web browser project which was fully java code. I want some information ragarding to that project. First I used JEditorPane for displaying HTML Content. But it was not executing JavaScript. My friend told that JEditorPAne was rendering HTML pages of HTML3.2 version. It wont render Javascript. So try for other things.
    I used IECanvas but it just embedding the component of Internet Explorer or Mozilla. I don't want to embed those things. I need java components only. After that I have to do Charecter Encoding on that one. Pls anybody help me regarding to this matter. Its Urgent

    Dear hiwa,
    I saw the JDIC API. They told that it embeds some predefined browsers called INTERNET EXPLORER. But I don't want to embed these things. Is there any solution other than this? U saw ICE Browser. it was implemented in fully java having many functionalities.It is third party API. I tried to use that API but they gave 30 days trail period. So I am afried of that. I just want to display the HTML page that supports JavaScript. I saw rhino which is an Interpreter for javascript.
    Is there any possibility to embed this interpreter to JEditorPane or any java component. Pls give me details if Possible.
    thanks for your kind information.

  • Cookies and JFrame Web Browser

    Hello,
    Currently I'm trying to analyze of making a java web browser. I have found several versions of code that enable JFrame of Java to be a web browser, some even go as far as having a back anf forth feature and history. The only thing I cannot find is how to save and use cookies. While I found some things that allow code to save cookies, I need some help in implementing into the web browser. The web browser currently works but if I try something that require a cookie, like logging into gmail, it will tell that I need to have cookies enable (likely to be capable to take cookies and then use them).
    Does anyone know a way to do that? Or know what direction to look?

    Anyone?

  • Email and web browser MHP 1.0

    Hi all,
    Has anybody implemented and email client and a web browser for MHP 1.0.2?
    Are there open source tools to help me on the implementation on these applications, like a Jave email client and a Java web browser that I can convert easily to MHP?
    What Java classes I need to use to implement the email and browser?
    Does any STB in the market support MHP 1.1?
    I want to hear your opinions...
    Thanks in advance,
    Jordi (Barcelona)

    Dear Jordi
    We have created a java browser that runs very well in mhp, and you can run a webmail service on it as will. You can get a 2 months free evaluation version. Please see www.nordcom.dk for details on how to get the evaluation version.
    Best regards
    Thorbj�rn Vynne
    NordCom Interactive

  • JMF and web browser GUI

    hi,
    i have made a java web browser and i would like to add sound events to the gui JButtons ("back","next", etc.).
    I would also like to add a text to speech funtion that reads the text between <BODY> .... </BODY> in the HTML docs open in the browser JEditorPane.
    If anyone has any experiece with this I would really appreciate thier help.
    THANKS!!

    Hi BradW,
    The way this is supposed to be done in Web Cache is by keeping separate copies of a cached page for different types of browsers distinguished by User-Agent header.
    In case of cache miss, Web Cache expects origin servers to return appropriate version of the page based on browser type, and the page from the origin server is just forwarded back to browser.
    Here, if the page is cacheable, Web Cache retains a separate copy for each type of User-Agent header value.
    And when there is a hit on this cached page, Web Cache returns the version of page with the User-Agent header that matches the request.
    Check out the config screen titled "Header Association" for this feature.
    About forwarding requests to different origin servers based on User-Agent header value, Web Cache does not have such capability.

  • Opening a web browser from a Java prog

    I am writing a pseudo-wordprocessor, and would like to be able to set a JMenuItem's action so that when a user clicks it, the system default web browser opens with the web page that I have selected. (e.g. open up a "Help" web page).
    The JavaDoc/tutorial doesn't seem to have anything on running external programs from within a Java program, so does nayone know how this is done?

    If you don't want to go the Java Runtime route and make your program a bit more cross-platform friendly, you could use the JEditorPane to render an html page directly in your application (assuming of course that you're using Swing).

  • Portal with a URL using a Web browser in java stack

    Dear all,
    I can access the portal with our URL using a Web browser from your client machines .
    i got the following option :
    SAP Library
    SAP Library contains the complete documentation for SAP Web Application Server.
    Web Services Navigator
    Web Services Navigator is a tool that gives you a short overview of a specific Web service based on its WSDL, and enables you to test your Web service by creating and sending a client request to the real end point.
    System Information
    System information provides administrators with an overview of the system configuration and its state. It shows all of the system's instances and processes, their current state and important parameters (such as ports) that may be required for support cases, as well as the versions of the components installed.
    UDDI Client
    The UDDI client provides query and publishing functions for different Web service entities (tModels, business services) to any UDDI compliant registry.
    User Management
    The user management administration console provides administrators with the functions they need to manage users, groups, roles, and user-related data in the User Management Engine (UME). Users without administrator permissions can use it to change their user profile.
    Web Dynpro
    Web Dynpro is a User Interface technology available within the SAP NetWeaver Developer Studio.
    Various Web Dynpro tools provide administrators and application developers with performance measurement and application administration capabilities. The Web Dynpro runtime is already deployed.
    SAP NetWeaver Administrator
    A tool for administration and monitoring, offering a central entry point to the whole SAP NetWeaver system landscape. The SAP NetWeaver Administrator can be used in a central scenario where it is capable of operating an entire system landscape containing ABAP and Java systems as the application platform of SAP NetWeaver.
    J2EE Engine Examples
    This section contains several J2EE application examples that run on the J2EE Engine. The examples show some of the functions of both Java and the J2EE Engine. They can be easily deployed and tested by simply clicking on a button. The full source code of the examples is also available.
    when i click System Information:
    it ask user name () J2EE_ADMINand password (Installtion master password) ,after entered , i got below error .
    You are not authorized to view the requested resource.
      Details:   No details available
    Kindly suggest .

    Hello
    It means what it sais, your J2EE_ADMIN user doesn't have enough authorization.
    Chech if the appropriate authorization is assigned in your abap stack which belongs to the java stack you logon to:
    Role SAP_J2EE_ADMIN should be assigned to user J2EE_ADMIN.
    Kind regards
    Tom
    Edited by: Tom Cenens on Dec 17, 2010 2:55 PM

  • Java does not work on my Win 7 IBM-compatible PC using Firefox as my web browser

    A typical example of a website I would like to access & view is "www'cut-the-knot.org", a relatively mathematics-related website with a lot a very nice math content, where (roughly estimating) 70-90% of all web pages on the web site use Java applets to communicate that math content.
    I CANNOT view the Java applets (am restricted/prevented from doing so) --- on CTK or ANY other website!.
    I could go into all the details but, essentially, I have tried just about everything I can think of (or have found to do/try in discussions on the Internet by googling the problem) & nothing seems to have had any positive affect ... I can still not view ANY Java applets on ANY website! :-(
    I USED to be able to view Java content on the PC I was working on, although, a few months ago, I migrated from Win XP to Win 7 when MS stopped supported Win XP. I don't know when things changed but, "while I wasn't looking" (&/or paying attention) something DID change. :-(
    I'm using an IBM-compatble PC (not a Mac) with Windows 7 & Firefox as my web-browser.
    I'm just a private individual ... just a "little guy" in my home ... little personal technical knowledge, no big biz connections, no $ to hire expensive (or inexpensive) experts to come in & assess & fix the problem. I would even just like to know if there is some kind of future expected date when something MIGHT get improved, barring an action "solution" of the problem.
    From what I read on the Internet, some problem(s) relating to this issue has/have been extant for at least two years, dating back to at least 2012, if not further? I assume the problem would have been fixed long ago if it were easy to fix so, I'm not trying to be overly critical ... just asking for some kind of status report --- help/communication/knowledge/expertise/solution/etc ... & any information would be appreciated. Knowing WHAT the problem is is a high priority to me, certainly as well as understanding HOW TO FIX the problem, & WHEN that fix will occur.
    Java is a seemingly wonderful technology but, if there are such severe security risks that require it be enabled so that no one (I'll assume I'm not the only one unable to view Java applets) can use it, it doesn't have much value to visitors to websites that employ Java to deliver a majority of their content. Part of the problem, obviously, is that (like CTK) MANY websites ALREADY use/employ Java --- & therefore, end-users have almost no access to the content in/on those websites.
    Thanx in advance ...
    arbmm7
    (2014-08-30-1023 PST)
    PS - Just before posting this comment, I clicking a button at the bottom of the Mozilla web page that said it had "guessed" at current browser & OS, & the following is what was "reported":
    Firefox version 32
    Windows 7 OS
    * Shockwave Flash 14.0 r0
    * Adobe PDF Plug-In For Firefox and Netscape 10.1.11
    * Next Generation Java Plug-in 11.11.2 for Mozilla browsers
    * NPRuntime Script Plug-in Library for Java(TM) Deploy
    * VLC media player Web Plugin 2.1.3

    PS - SORRY --- I meant (in the title): "... using Firefox as my web browser."

  • Possible to read data from a web browser into java?

    Is it possible to read data from a web browser such as IE or Mozilla into a java applet for use and manipulation? If it is, could someone please post some documentation I could look at or a snip-it of code I could use? Thanks.

    This will read the content from a site:
    import java.net.*;
    import java.io.*;
    class Test {
         public static void main(String[] argv) throws Exception {
              URL u = new URL("http://www.google.com");
              URLConnection uc = u.openConnection();
              BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
              String text;
              while( (text = br.readLine()) != null ) {
                   System.out.println(text);
    }

  • Running a Java application from web browser

    Hi,
    I'm not sure if this is the right place to put this, and it probably isn't, but I don't really know what else to do at the moment.
    I have a problem. I've written all these nice and pretty Java applications that do all this complicated junk that makes me proud. However...I have no idea how to actually run those applications.
    I've looked at guides on Java applets, Java Web Start, Java Server Pages, etc, and I still am not sure. JSP looked like the best option, until I figured out I can't use it with my web server. So, I've pretty much hit a wall here.
    If anyone could shed some light on this, I would be very appreciative. All I want is for a certain application to run when a user clicks a button on a simple HTML page. That's all I want...yet it seems so hard.
    Is there a simple way to do this, or do I need to use JWS or something and configure all these JARs and JNLP and classpaths and everything under the sun (no pun intended)?
    Again, I apologize if there is a better forum for this; I am just very confused right now and feel like I've hit a brick wall. If anyone can give me any advice, or point me in a good (easy) direction, I would truly be grateful.

    If anyone could shed some light on this, I would be
    very appreciative. All I want is for a certain
    application to run when a user clicks a button on a
    simple HTML page. That's all I want...yet it seems so
    hard. There's a lot of hidden details that make it so hard. What computer will run the application when the button is clicked? If the application will run on the client computer (within the web browser) there has to be a mechanism for allowing arbitrary code to be downloaded, verified and executed on any number of different target platforms. This is the problem that Java Applets address. Mostly this is a security issue, since a simple HTML page being able to run arbitary code without user interaction or approval is going to cause the world to be overrun by computer virii. There's also the multi-platform issue, but in many cases that can be avoided by requiring the client to use a single platform (the MS approach).
    If the application will run on the server, then the client code is much less difficult, as only a basic web browser is needed, and the server code is complicated, since it needs to keep track of multiple clients at the same time and process data in a request-response fashion.
    From the end-user's point-of-view, it certainly is simple though. Press the button and voila!
    "Any technology which is distinguishable from magic is insufficiently advanced"
    Brian

Maybe you are looking for