Developing a browser in java

Hi All,
i want to know whether i can develop a browser using java swings..If so where i can get more details on this...
can anyone help me..
Thanks..
ramya

I Have developed one such basic application employing JEditorPane. The Code is as follows
ReadServerFile.java
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
public class ReadServerFile extends JFrame {
     private JTextField enter;
     private JButton go;
     private JEditorPane contents;
     JToolBar jtb;
     JScrollPane jsp;
     JButton jbLoad,jbUnload,jbDesc,jbFind,jbSave,jbPrint,jbGet,jbGetNext,jbGetBulk,jbSet,jbBrow,jbTrap,jbGraph,jbTable,jbDebug,jbClear,jbStop,jbHelp,jbExit;
     public ReadServerFile() {
          super("Simple web browser");
          getContentPane().setLayout(null);
          int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
          int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
          Container c = getContentPane();
          enter = new JTextField("Enter file url");
          enter.addActionListener( new ActionListener(){
                    public void actionPerformed(ActionEvent e){
                         getThePage(e.getActionCommand());
          enter.setBounds(25,50,500,30);
          c.add(enter);
          //c.add(enter,BorderLayout.NORTH);
          go = new JButton("Go");
          go.setBounds(550,50,75,30);
          c.add(go);
          contents = new JEditorPane();
          contents.setEditable(false);
          contents.addHyperlinkListener( new HyperlinkListener() {
                    public void hyperlinkUpdate(HyperlinkEvent e){
                         if(e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
                         getThePage(e.getURL().toString());
          //c.add(new JScrollPane(contents), BorderLayout.CENTER);
          jsp = new JScrollPane(contents,v,h);
          //contents.setBounds(25,100,650,400);
          jsp.setBounds(25,100,700,450);
          c.add(jsp);
          Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
          setBounds(0,0,screenSize.width,screenSize.height);
               jtb = new JToolBar(0);
                    jbLoad      = addToolButton(jbLoad,new ImageIcon("load.jpg"),"Load MIB Module");
                    jbUnload      = addToolButton(jbUnload,new ImageIcon("unload.jpg"),"UnLoad MIB Modules");
                    jbDesc          = addToolButton(jbDesc,new ImageIcon("describe.jpg"),"Description");
                    jbFind          = addToolButton(jbFind,new ImageIcon("find.jpg"),"Find MIB Node");
                    jbSave = addToolButton(jbSave,new ImageIcon("saveresult.jpg"),"Save MIB browser results");
                    jbPrint          = addToolButton(jbPrint,new ImageIcon("printresult.jpg"),"Print MIB browser results");
                    jbGet          = addToolButton(jbGet,new ImageIcon("get.jpg"),"Get SNMP variable");
                    jbGetNext     = addToolButton(jbGetNext,new ImageIcon("getnext.jpg"),"Get Next SNMP variable");
                    jbGetBulk = addToolButton(jbGetBulk,new ImageIcon("getbulk.jpg"),"GetBulk SNMP data");
                    jbSet          = addToolButton(jbSet,new ImageIcon("set.jpg"),"Set SNMP variable");
                    jbBrow          = addToolButton(jbBrow,new ImageIcon("settings.jpg"),"MIB browser settings");
                    jbTrap          = addToolButton(jbTrap,new ImageIcon("trap.jpg"),"Trap viewer");
                    jbGraph          = addToolButton(jbGraph,new ImageIcon("graph.jpg"),"View real time graph");
                    jbTable          = addToolButton(jbTable,new ImageIcon("table.jpg"),"View SNMP table data");
                    jbDebug          = addToolButton(jbDebug,new ImageIcon("debug.jpg"),"Debug");
                    jbClear          = addToolButton(jbClear,new ImageIcon("clear.jpg"),"Clear results display");
                    jbStop          = addToolButton(jbStop,new ImageIcon("stop.jpg"),"Stop");
                    jbHelp          = addToolButton(jbHelp,new ImageIcon("help.jpg"),"Help");
                    jbExit      = addToolButton(jbExit,new ImageIcon("exit.jpg"),"Exit");
jtb.setBounds(10,10,400,60);
c.add(jtb);
          //setSize(400,300);
          show();
     } // end of constructor
          private void getThePage(String location){
          setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
          try{
               contents.setPage(location);
               enter.setText(location);
          catch(IOException io) {
               JOptionPane.showMessageDialog(this,"Error retrieving specified url","Bad url",JOptionPane.ERROR_MESSAGE);
          setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
          } // end of getThePage
          public JButton addToolButton(JButton name,ImageIcon image,String tooltip)
                    name=new JButton(image);
                    name.setBorderPainted(false);
                    name.setFocusPainted(false);
          // name.addMouseListener(this);
                    name.setToolTipText(tooltip);
          name.setMargin(new Insets(0, 1, 0, 1));
          name.getAccessibleContext().setAccessibleName(tooltip);
          name.setActionCommand(tooltip);
                    jtb.add(name);
                    return name;
          public static void main(String args[]) {
          ReadServerFile app = new ReadServerFile();
          app.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e)
          { System.exit(0);} } );
     } // end of Main
} // end of this class
For any other details contact me at [email protected]

Similar Messages

  • To Develop a Browser using Java

    Hi,
    I want to know if it is possible to write a browser using java.If so where can i get more information regarding this.
    Juz let me know the details.
    Thanks in advance...
    ramya

    Dear Ramya,
    You can use JEditorPane with setEditable(false) as the HTML rendering engine. For other components, you have to look elsewhere.
    S. Senthil kumar

  • Browsing through java

    Hello,
    I am developing a simple browser in java.my problems are listed below.
    1.when i connect to website using the url(Using a socket connection) i receive whole HTML code along the text in the console and no images.how can i display the web page on the JPanel in my frame with images and links.
    2.how should i add caching feature in my browser.
    3.what should be done in the event handling of the refresh button.
    4.how to add text selection and copying feature in my browser using mouse.

    1) Getting images requires interpreting the Html response. The images are included as Urls and should be fetched in separate requests.
    2) You should look at the Http response and look for cache headers.

  • Difficulty in developing a Browser?

    hi guys,
    I am developing a web browser in java. I am able to display simple HTML page but when it comes to Applet and JavaScript it is not working. I am using JEditorPane for browser window for displaying pages. The browser is unable to display Applet, JavaScript, Flash and advanced HTML tags.
    Can anyone help me regarding this? Does anyone have an idea as to how to make a browser to understand various plug-ins regarding the above types?

    Please get me the solution of this problem.Sorry, I don't have a time machine to port you back in time long enough for you to create a full featured web browser in time for delivery next month, especially given the fact that I'd also need to ship a powerstation, a transformer, and everything needed to run that powerstation for a few million years.
    And that's before starting on the youth drugs you'd need to be able to survive those millions of years and keep working.

  • Difficulty in developing a Browser? 2 duke dollors

    hi guys,
    I am developing a web browser in java. I am able to display simple HTML page but when it comes to Applet and JavaScript it is not working. I am using JEditorPane for browser window for displaying pages. The browser is unable to display Applet, JavaScript, Flash and advanced HTML tags.
    Can anyone help me regarding this? Does anyone have an idea as to how to make a browser to understand various plug-ins regarding the above types?

    hi, there is a java library called JDIC (Java Desktop Integration Component) that u can use to create such a browser.
    Here is the url, http://jdic.dev.java.net .

  • Difficulty in developing a Browser? 10 Dukes

    hi guys,
    I am developing a web browser in java. I am able to display simple HTML page but when it comes to Applet and JavaScript it is not working. I am using JEditorPane for browser window for displaying pages. The browser is unable to display Applet, JavaScript, Flash and advanced HTML tags.
    Can anyone help me regarding this? Does anyone have an idea as to how to make a browser to understand various plug-ins regarding the above types?

    JEditorPane really isn't up to the task on its own.
    A quick search on Google for "java browser component" came up with three possibilities straight away. Perhaps you should try there first?
    Hope this helps.

  • I hope to develop a function with java like IE's save as.How can I do?

    I hope to develop a function with java like IE's save as.How can I do?

    hi ,
    Considering IE browser page as an object, U can use Serialization where u can save that object.(i.e state of the object) And then when u open it thru de-serialization, u can restore the page/object .
    Hope that helps U .
    Techie.

  • How to create and install a toolbar to a browser using java

    Hi all,
    Can any one guide me about how to create and install toolbar to a browser using java ??
    please any one help me about this,i am not getting any idea about this..
    Thanks and Regards
    Sandesh S

    I doubt you can. Those browser toolbars are done by implementing to an API provided by the browser. That API, I don't believe, is provided via Java. But of course, that would be entirely up to the browser, not Java.

  • How to display Map for viewing in browser using Java

    I am fidning a solution for displaying political maps in browser using Java technology.
    Is ther anybody with a solution.
    Waiting for your respone.
    Regards
    Mithun

    palanithendral wrote:
    Hi,
    Our application using in English, German, Franch and chinese.You have several different idioms in your application and have not accurately identified where the actual problem is. You have all of the following
    -database
    -http
    -excel
    -excel in http
    -display on the target computer
    The first step with these sorts of problem is to identify where the problem actually occurs.
    String chineseCharacter=""; // chineseCharacter like 長长牀床東东彿佛. This chinese data coming from oracle database..A good theory. Now explain how you proved that that is what is coming from the database.
    After export the data to excel show the result for 長长牀床東东彿佛.As another example. Presumably you are referring to what the browser on the target computer displays. Your theory is that that computer and that browser (together) will display the correct information if they had the correct data. How did you prove that?

  • How do i  open browser in java application

    hi....
    please help me!!!!!!!!!!!!!!!!!!!!!!!!!!
    how do i open browser in java application ? ( for show javascript in java application)
    thank you.......

    You can run any program from java by doing
    Runtime.getRuntime().exec("mybrowser myjavascriptfile.js");
    The real question is why would you want to.
    I would suggest you rethink whether running Javascript from Java is a good idea.

  • Launching Browser from Java when Browser URL is very  long

    Hi,
    I am trying to launch a browser from Java.
    I am doing the following.
    String command = "cmd" + "/c" + "start" + " browserURL";
    Process p = Runtime.getRuntime()exec(command);
    Note: My browserURL is very long.
    Now the browser is invoked. But the URL shown is incomplete and hence
    browser is unable to open the required application.
    Can someone help me in this.
    One way is to increase the buffer size on the command prompt?
    Is there any java command for this?
    Is there any other way to solve this issue.
    Thanks,
    AR

    this is my second time posting this, take note of it. I can't remember where i got it from, but credits go to the person that wrote it. It has helped me out thousands of times!!!
    to use, compile, then call from your program:
    org.newio.utils.BrowserLauncher.openURL("your url here")dfwtc
    package org.newio.utils;
    import java.io.File;
    import java.io.IOException;
    import java.lang.reflect.*;
    public class BrowserLauncher
        private static int jvm;
        private static Object browser;
        private static boolean loadedWithoutErrors;
        private static Class mrjFileUtilsClass;
        private static Class mrjOSTypeClass;
        private static Class macOSErrorClass;
        private static Class aeDescClass;
        private static Constructor aeTargetConstructor;
        private static Constructor appleEventConstructor;
        private static Constructor aeDescConstructor;
        private static Method findFolder;
        private static Method getFileType;
        private static Method makeOSType;
        private static Method putParameter;
        private static Method sendNoReply;
        private static Object kSystemFolderType;
        private static Integer keyDirectObject;
        private static Integer kAutoGenerateReturnID;
        private static Integer kAnyTransactionID;
        private static final int MRJ_2_0 = 0;
        private static final int MRJ_2_1 = 1;
        private static final int WINDOWS_NT = 2;
        private static final int WINDOWS_9x = 3;
        private static final int OTHER = -1;
        private static final String FINDER_TYPE = "FNDR";
        private static final String FINDER_CREATOR = "MACS";
        private static final String GURL_EVENT = "GURL";
        private static final String FIRST_WINDOWS_PARAMETER = "/c";
        private static final String SECOND_WINDOWS_PARAMETER = "start";
        private static final String NETSCAPE_OPEN_PARAMETER_START = " -remote 'openURL(";
        private static final String NETSCAPE_OPEN_PARAMETER_END = ")'";
        private static String errorMessage;
        private BrowserLauncher()
        private static boolean loadClasses()
            switch(jvm)
            default:
                break;
            case 0: // '\0'
                try
                    Class aeTargetClass = Class.forName("com.apple.MacOS.AETarget");
                    macOSErrorClass = Class.forName("com.apple.MacOS.MacOSError");
                    Class osUtilsClass = Class.forName("com.apple.MacOS.OSUtils");
                    Class appleEventClass = Class.forName("com.apple.MacOS.AppleEvent");
                    Class aeClass = Class.forName("com.apple.MacOS.ae");
                    aeDescClass = Class.forName("com.apple.MacOS.AEDesc");
                    aeTargetConstructor = aeTargetClass.getDeclaredConstructor(new Class[] {
                        Integer.TYPE
                    appleEventConstructor = appleEventClass.getDeclaredConstructor(new Class[] {
                        Integer.TYPE, Integer.TYPE, aeTargetClass, Integer.TYPE, Integer.TYPE
                    aeDescConstructor = aeDescClass.getDeclaredConstructor(new Class[] {
                        java.lang.String.class
                    makeOSType = osUtilsClass.getDeclaredMethod("makeOSType", new Class[] {
                        java.lang.String.class
                    putParameter = appleEventClass.getDeclaredMethod("putParameter", new Class[] {
                        Integer.TYPE, aeDescClass
                    sendNoReply = appleEventClass.getDeclaredMethod("sendNoReply", new Class[0]);
                    Field keyDirectObjectField = aeClass.getDeclaredField("keyDirectObject");
                    keyDirectObject = (Integer)keyDirectObjectField.get(null);
                    Field autoGenerateReturnIDField = appleEventClass.getDeclaredField("kAutoGenerateReturnID");
                    kAutoGenerateReturnID = (Integer)autoGenerateReturnIDField.get(null);
                    Field anyTransactionIDField = appleEventClass.getDeclaredField("kAnyTransactionID");
                    kAnyTransactionID = (Integer)anyTransactionIDField.get(null);
                    break;
                catch(ClassNotFoundException cnfe)
                    errorMessage = cnfe.getMessage();
                    return false;
                catch(NoSuchMethodException nsme)
                    errorMessage = nsme.getMessage();
                    return false;
                catch(NoSuchFieldException nsfe)
                    errorMessage = nsfe.getMessage();
                    return false;
                catch(IllegalAccessException iae)
                    errorMessage = iae.getMessage();
                return false;
            case 1: // '\001'
                try
                    mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");
                    mrjOSTypeClass = Class.forName("com.apple.mrj.MRJOSType");
                    Field systemFolderField = mrjFileUtilsClass.getDeclaredField("kSystemFolderType");
                    kSystemFolderType = systemFolderField.get(null);
                    findFolder = mrjFileUtilsClass.getDeclaredMethod("findFolder", new Class[] {
                        mrjOSTypeClass
                    getFileType = mrjFileUtilsClass.getDeclaredMethod("getFileType", new Class[] {
                        java.io.File.class
                    break;
                catch(ClassNotFoundException cnfe)
                    errorMessage = cnfe.getMessage();
                    return false;
                catch(NoSuchFieldException nsfe)
                    errorMessage = nsfe.getMessage();
                    return false;
                catch(NoSuchMethodException nsme)
                    errorMessage = nsme.getMessage();
                    return false;
                catch(SecurityException se)
                    errorMessage = se.getMessage();
                    return false;
                catch(IllegalAccessException iae)
                    errorMessage = iae.getMessage();
                return false;
            return true;
        private static Object locateBrowser()
            if(browser != null)
                return browser;
            switch(jvm)
            case 0: // '\0'
                try
                    Integer finderCreatorCode = (Integer)makeOSType.invoke(null, new Object[] {
                        "MACS"
                    Object aeTarget = aeTargetConstructor.newInstance(new Object[] {
                        finderCreatorCode
                    Integer gurlType = (Integer)makeOSType.invoke(null, new Object[] {
                        "GURL"
                    Object appleEvent = appleEventConstructor.newInstance(new Object[] {
                        gurlType, gurlType, aeTarget, kAutoGenerateReturnID, kAnyTransactionID
                    return appleEvent;
                catch(IllegalAccessException iae)
                    browser = null;
                    errorMessage = iae.getMessage();
                    return browser;
                catch(InstantiationException ie)
                    browser = null;
                    errorMessage = ie.getMessage();
                    return browser;
                catch(InvocationTargetException ite)
                    browser = null;
                    errorMessage = ite.getMessage();
                    return browser;
            case 1: // '\001'
                File systemFolder;
                try
                    systemFolder = (File)findFolder.invoke(null, new Object[] {
                        kSystemFolderType
                catch(IllegalArgumentException iare)
                    browser = null;
                    errorMessage = iare.getMessage();
                    return browser;
                catch(IllegalAccessException iae)
                    browser = null;
                    errorMessage = iae.getMessage();
                    return browser;
                catch(InvocationTargetException ite)
                    browser = null;
                    errorMessage = ite.getTargetException().getClass() + ": " + ite.getTargetException().getMessage();
                    return browser;
                String systemFolderFiles[] = systemFolder.list();
                for(int i = 0; i < systemFolderFiles.length; i++)
                    try
                        File file = new File(systemFolder, systemFolderFiles);
    if(file.isFile())
    Object fileType = getFileType.invoke(null, new Object[] {
    file
    if("FNDR".equals(fileType.toString()))
    browser = file.toString();
    return browser;
    catch(IllegalArgumentException iare)
    browser = browser;
    errorMessage = iare.getMessage();
    return null;
    catch(IllegalAccessException iae)
    browser = null;
    errorMessage = iae.getMessage();
    return browser;
    catch(InvocationTargetException ite)
    browser = null;
    errorMessage = ite.getTargetException().getClass() + ": " + ite.getTargetException().getMessage();
    return browser;
    browser = null;
    break;
    case 2: // '\002'
    browser = "cmd.exe";
    break;
    case 3: // '\003'
    browser = "command.com";
    break;
    case -1:
    default:
    browser = "netscape";
    break;
    return browser;
    public static void openURL(String url)
    throws IOException
    if(!loadedWithoutErrors)
    throw new IOException("Exception in finding browser: " + errorMessage);
    Object browser = locateBrowser();
    if(browser == null)
    throw new IOException("Unable to locate browser: " + errorMessage);
    switch(jvm)
    case 0: // '\0'
    Object aeDesc = null;
    try
    try
    aeDesc = aeDescConstructor.newInstance(new Object[] {
    url
    putParameter.invoke(browser, new Object[] {
    keyDirectObject, aeDesc
    sendNoReply.invoke(browser, new Object[0]);
    catch(InvocationTargetException ite)
    throw new IOException("InvocationTargetException while creating AEDesc: " + ite.getMessage());
    catch(IllegalAccessException iae)
    throw new IOException("IllegalAccessException while building AppleEvent: " + iae.getMessage());
    catch(InstantiationException ie)
    throw new IOException("InstantiationException while creating AEDesc: " + ie.getMessage());
    break;
    finally
    aeDesc = null;
    browser = null;
    case 1: // '\001'
    Runtime.getRuntime().exec(new String[] {
    (String)browser, url
    break;
    case 2: // '\002'
    case 3: // '\003'
    Runtime.getRuntime().exec(new String[] {
    (String)browser, "/c", "start", url
    break;
    case -1:
    Process process = Runtime.getRuntime().exec((String)browser + " -remote 'openURL(" + url + ")'");
    try
    int exitCode = process.waitFor();
    if(exitCode != 0)
    Runtime.getRuntime().exec(new String[] {
    (String)browser, url
    catch(InterruptedException ie)
    throw new IOException("InterruptedException while launching browser: " + ie.getMessage());
    break;
    default:
    Runtime.getRuntime().exec(new String[] {
    (String)browser, url
    break;
    static
    loadedWithoutErrors = true;
    String osName = System.getProperty("os.name");
    if("Mac OS".equals(osName))
    String mrjVersion = System.getProperty("mrj.version");
    String majorMRJVersion = mrjVersion.substring(0, 3);
    try
    double version = Double.valueOf(majorMRJVersion).doubleValue();
    if(version == 2D)
    jvm = 0;
    } else
    if(version >= 2.1000000000000001D)
    jvm = 1;
    } else
    loadedWithoutErrors = false;
    errorMessage = "Unsupported MRJ version: " + version;
    catch(NumberFormatException numberformatexception)
    loadedWithoutErrors = false;
    errorMessage = "Invalid MRJ version: " + mrjVersion;
    } else
    if(osName.startsWith("Windows"))
    if(osName.indexOf("9") != -1)
    jvm = 3;
    } else
    jvm = 2;
    } else
    jvm = -1;
    if(loadedWithoutErrors)
    loadedWithoutErrors = loadClasses();
    suck my balls

  • Does the iphone browser support java

    does the iphone browser support java?
    can it run java applets?

    No, there is no Java support in the iPhone. (There is javascript, but that's obviously quite different.)
    You can submit feedback to Apple: http://www.apple.com/feedback/iphone.html

  • How to detect whether browser's java script  disabled or not from server

    How to detect whether browser's java script disabled or not from server side

    I would use a hidden parameter created by a javascript. if this is null, javascript is disabled...

  • Which is best web service framework for developing web services in Java?

    Hi Friends,
    I want to develop web services using Java 1.5.
    But I am in confusion with different frameworks provides to develop WS.
    Like
    1) Apache axis
    2) Java Web Service dev. Pack
    3) JSON-RPC-Java
    4) Web Ser. Invocation Pack
    5) XFire
    Can some one guide which framework should I use?
    OR where will i get useful comparison between this frameworks?

    Hi,
    Personally I have used:
    1. XFire
    2. Apache Axis
    3. Java Web Service Pack
    My personal opinion / .02 cents?
    1. XFire is awesome and very easy to set up and get running. They also have a great community / mailing lists. We use it in some production systems and it runs great.
    2. Apache AXIS 1/2 made me want to dive out the window and go splat just short of the double yellow line on the road. Pain in the butt to set up and get running. Way too complex. Really bad docs / tutorials / support.
    3. Java Web Service Pack - I really prefer NetBeans 5.5 and the JWSP. Easy to build services, cohesive enviroment. You can get the job done.
    That's my two cents.
    M Goodell

  • Close parent window of Mozilla browser from Java

    Hi All,
    I want to open a URL in a controlled browser from java stand alone application. I was able to do this in Netscape of UNIX OS. The method followed is given below.
    1. Launch a temporary HTML file which contains Javascript (to launch the URL in a controlled window). This is done using --- Runtime.getRuntime().exec() method.
    2. Close the parent HTML file on 'onLoad' using Javascript. (self.close).
    [ I tried window.close() & top.close() also.]
    Now I need to support the same for "Mozilla" also. But mozilla just ignores the close() command of Javascript.
    1. Is there any alternative way to close the parent window in Mozilla browser ?
    2. Is there any way to close the parent window from java by using 'Process' class/ threads/ ??
    3. Any other way???
    Note : I am using the intermediate window for using Javascript. (controlling the browser properties). Since Java cannot communicate to Javascript directly, I am forced to have such an intermediate HTML file.
    Thanks in advance.
    surekha_Venugopal.

    Some more details :
    Mozilla browser will close a window using window.close() command, but only if the window is opened by the script. If not it will not close it.
    Here, I am opening the window from Java application. That is why closure of the window is failing.
    Trying to find a solution.
    Regards,
    Surekha_Venogopal

Maybe you are looking for