Swing web browser...

Is there any good sort of like.. wrapper object to contain the system's default browser to embed in a Swing app? I've looked at using a JEditorPane, but its functionality seems rather limited. I've also considered using the Desktop object to launch the system's default browser, but for my purposes this will be inadequate. What I really need is some kind of wrapper type object that launches the default browser within a Swing panel. Anyone know if there's anything like this implemented?

I'm not getting any results from that in google... maybe you're talking about java.awt.Desktop? This is something I've already tried to use, but it's not really adequate for my purposes.

Similar Messages

  • Swing components in applet not working in web browser

    Hi Guys,
    I've created an applet which makes use of some swing components, but unfortunately, not all of them function properly in my web browser (internet explorer or Mozilla Firefox). Its mainly the buttons; the last buttons works and displays the correct file within the broswer, but the first 5 buttons do not work...
    any help please on how I can sort this problem out?
    Heres the code for my applet:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.applet.*;
    public class MainAppWindow extends JApplet
    int gapBetweenButtons = 5;
    final JPanel displayPanel = new JPanel(new BorderLayout());
    public void init()
       //Panel for overall display in applet window.
       JPanel mainPanel = new JPanel(new BorderLayout());
       mainPanel.add(new JLabel(new ImageIcon(getClass().getResource("images/smalllogo2.gif"))),BorderLayout.NORTH);
       //sub mainPanel which holds all mainPanels together.
       JPanel holdingPanel = new JPanel(new BorderLayout());
       //Panel for displaying all slide show and applications in.
       displayPanel.setBackground(Color.white);
       displayPanel.add(new JLabel(new ImageIcon(getClass().getResource("images/IntroPage.jpg"))),BorderLayout.CENTER);
       displayPanel.setPreferredSize(new Dimension(590,400));
       JPanel buttonPanel = new JPanel(new GridLayout(6,1,0,gapBetweenButtons));
       buttonPanel.setBackground(Color.white);
       JButton button1 = new JButton("User guide");
       button1.addActionListener(
         new ActionListener() {
              public void actionPerformed(ActionEvent e)
                   if(displayPanel.getComponents().length > 0)displayPanel.removeAll(); // If there are any components in the mainPanel, remove them and then add label
                   displayPanel.setBackground(Color.white);
                   displayPanel.add(new JLabel(new ImageIcon("images/UserGuide.jpg")));
                   displayPanel.revalidate(); // Validates displayPanel to allow changes to occur onto it, allowing to add different number images/applicaions to it.
       JButton button2 = new JButton("What is a Stack?");
       button2.addActionListener(
       new ActionListener() {
               public void actionPerformed(ActionEvent e)
                   if(displayPanel.getComponents().length > 0)displayPanel.removeAll();
                   displayPanel.setBackground(Color.white);
                   displayPanel.add(new JLabel(new ImageIcon("images/WhatIsAStack.jpg")));
                   displayPanel.revalidate();
       JButton button3 = new JButton("STACK(ADT)");
       button3.addActionListener(
       new ActionListener() {
             public void actionPerformed(ActionEvent e)
                   if(displayPanel.getComponents().length > 0)displayPanel.removeAll();
                   displayPanel.setBackground(Color.white);
                   displayPanel.add(new JLabel(new ImageIcon("images/StackADT.jpg")));
                   displayPanel.revalidate();
       JButton button4 = new JButton("Stacks in the Real World");
       button4.addActionListener(
       new ActionListener() {
             public void actionPerformed(ActionEvent e)
                   if(displayPanel.getComponents().length > 0)displayPanel.removeAll();
                   displayPanel.setBackground(Color.white);
                   displayPanel.add(new JLabel(new ImageIcon("images/StacksInTheRealWorld.jpg")));
                   displayPanel.revalidate();
       JButton button5 = new JButton("DEMONSTRATION");
       button5.addActionListener(
       new ActionListener() {
             public void actionPerformed(ActionEvent e)
                 if(displayPanel.getComponents().length > 0)displayPanel.removeAll();
                 Demonstration app = new Demonstration();
                 JPanel appPanel = app.createComponents();//gets the created components from Demonstration application.
                 appPanel.setBackground(Color.pink);
               displayPanel.add(appPanel);
               displayPanel.revalidate();
       JButton button6 = new JButton("Towers Of Hanoi");
       button6.addActionListener(
       new ActionListener() {
             public void actionPerformed(ActionEvent e)
                     if(displayPanel.getComponents().length > 0)displayPanel.removeAll();
                     TowerOfHanoi app = new TowerOfHanoi();
                     JPanel appPanel = app.createComponents();//gets the created components from Towers of Hanoi
                     JPanel mainPanel = new JPanel();//panel used to centralise the application in center
                     mainPanel.add(appPanel);
                     mainPanel.setBackground(Color.pink); //sets mainPanel's background color for 'Towers Of Hanoi'
                     displayPanel.add(mainPanel);
                     displayPanel.revalidate();
       //adding buttons to the buttonPanel.
       buttonPanel.add(button1);
       buttonPanel.add(button2);
       buttonPanel.add(button3);
       buttonPanel.add(button4);
       buttonPanel.add(button5);
       buttonPanel.add(button6);
       JPanel p = new JPanel(); // Used so that the buttons maintain their default shape
       p.setBackground(Color.white);
       p.add(buttonPanel);
       holdingPanel.add(p,BorderLayout.WEST);
       holdingPanel.add(displayPanel,BorderLayout.CENTER);
       //Positioning of holdingPanel in mainPanel.
       mainPanel.add(holdingPanel,BorderLayout.CENTER);
       //indent mainPanel so that its not touching the applet window frame.
       mainPanel.setBorder(BorderFactory.createEmptyBorder(10,20,10,20));
       mainPanel.setBackground(Color.white);
       mainPanel.setPreferredSize(new Dimension(850,600)); //size of applet window
       mainPanel.setOpaque(false); // Needed for Applet
       this.setContentPane(mainPanel);
    }

    Thanks for the response. I don't quite understand what you're talking about though. I have, in my humble knowledge, done nothing with packages. I have put the applet class (WiaRekenToolActiz.class is the applet class) in the jar file wia_actiz_archive.jar. From what I read on the tutorial, java looks for the applet class in all the jar files specified. Since I put my CODEBASE as the main url, I thought it baiscally didn't matter where you out the html file.
    I shall include the complete html page complete with applet tag to perhaps illuminate a bit more what I mean...
    <html>
    <head>
    <title>Wia Rekenmodule hello!</title>
    </head>
    <body bgcolor="#C0C0C0">
    <applet
    CODEBASE= "http://www.creativemathsolutions.nl/test"
    ARCHIVE= "Actiz/wia_actiz_archive.jar, Generic/wia_archive.jar"
    CODE="WiaRekenToolActiz.class" 
    WIDTH=915 HEIGHT=555
    >
    <PARAM NAME = naam VALUE = "Piet Janssen">
    <PARAM NAME = gebdag VALUE = "01">
    <PARAM NAME = gebmaand VALUE = "06">
    <PARAM NAME = gebjaar VALUE = "1970">
    <PARAM NAME = geslacht VALUE = "man">
    <PARAM NAME = dienstjaren VALUE = "10">
    <PARAM NAME = salaris VALUE = "56500">
    <PARAM NAME = deeltijdpercentage VALUE = "100">
    <PARAM NAME = accountnaam VALUE = "Zorginstelling 'De Zonnebloem'">
    </applet>
    </body>
    </html>

  • A web browser in Swing

    Hi,
    I am writing a Lotus Notes add-in. In that I need to show a web page (which will have two applets). For this I need a browser control in Swing, in which this page can be displayed.
    Please suggest what should I use?
    Regards
    Nitin

    Hi,
    I tried using the same in my Lotus notes add-in, but received the following exception -
    java.lang.IllegalStateException: The version of SWT that is required is 3.7M5 or later!
    at chrriis.dj.nativeswing.swtimpl.core.SWTNativeInterface.initialize_(SWTNativeInterface.java:208)
    at chrriis.dj.nativeswing.swtimpl.NativeInterface.initialize(NativeInterface.java:71)
    at chrriis.dj.nativeswing.swtimpl.core.SWTNativeInterface.open_(SWTNativeInterface.java:315)
    at chrriis.dj.nativeswing.swtimpl.NativeInterface.open(NativeInterface.java:100)
    at test.SimpleWebBrowserExample.test(SimpleWebBrowserExample.java:56)
    at desktopapplication2.lotusconnector.start(lotusconnector.java:18)
    at desktopapplication2.JavaAgent.NotesMain(JavaAgent.java:16)
    at lotus.domino.AgentBase.runNotes(Unknown Source)
    at lotus.domino.NotesThread.run(Unknown Source)
    Even though swt-3.7M5-win32-win32-x86.jar(alongwith DJNativeSwing.jar and DJNativeSwing-SWT.jar) has already been imported in the library.
    The code in which I used it -
        JPanel webBrowserPanel = new JPanel(new BorderLayout());
        webBrowserPanel.setBorder(BorderFactory.createTitledBorder("Native Web Browser component"));
        final JWebBrowser webBrowser = new JWebBrowser();
        webBrowser.navigate(<some web url to browse to>);
        //webBrowserPanel.add(webBrowser, BorderLayout.CENTER);
        //add(webBrowserPanel, BorderLayout.CENTER);
        webBrowser.setMenuBarVisible(false);
        webBrowser.setLocationBarVisible(false);
        webBrowser.setBarsVisible(false);Regards
    Nitin

  • How to launch my java application in a web browser?

    Hi. I try to launch my java application, e.g. "HellowWorld.java", using web browser.
    1. How can I change my java application program to java applet in general way?
    I read "Java: An Introduction to Computer Science and Programming, Third Edition"
    by Walter Savitch and found page 803 - "Converting a Swing application to an applet".
    My question is how I can know which class should be removed or not such as using JApplet instead of JFrame. Are there general rules about this?
    2. I found "AWT only" tutorial had some example lauching application using "AppletButton".
    How can I use this method to launch "HelloWorld.class"?
    http://java.sun.com/docs/books/tutorial/information/download.html#OLDui
    (after extracting zip file) -> ../OLDui/layout/card.html
    3. (continued 2) Can I use above method to embed applet into web browser?
    For example, java Swing application -> applet using "AppletButton" -> web browser using "<applet></applet>" tag.
    I'd appreciate any partial anwers of these questions or other suggestions.
    Thanks.

    Thanks! Here is what I got from your help.
    * HelloWorldSwing.java is a 1.4 example that
    * requires no other files.
    import javax.swing.*;  
    import java.awt.*;                //for Container class    
    //  public class HelloWorldSwing {
       public class HelloWorldSwingToApplet extends JApplet {
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
    //    private static void createAndShowGUI() {
          private void createAndShowGUI() {
            //Make sure we have nice window decorations.
    //        JFrame.setDefaultLookAndFeelDecorated(true);
            //Create and set up the window.
    //        JFrame frame = new JFrame("HelloWorldSwing");
    //        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         Container frameApplet = getContentPane();
            //Add the ubiquitous "Hello World" label.
            JLabel label = new JLabel("Hello World");
    //        frame.getContentPane().add(label);
         frameApplet.add(label);
            //Display the window.
    //        frame.pack();
    //        frame.setVisible(true);
          public void init() {
           createAndShowGUI();
    /*    public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }

  • Web browser ...need help

    hello everyone..i have built a simple web browser using java..i can go to google.com or facebook.com but whenever i want to search something or want to login providing necessary information it doesnt work..can anyone tell me whats wrong here??nd how can i solve it?itz really urgent...
    here's my code :
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class Browser extends JFrame {
    private JTextField enterField;
    private JEditorPane contentsArea;
    //here's the GUI
    public Browser()
    super("MY BROWSER");
    Container container = getContentPane();
    enterField=new JTextField("enter file url here");
    enterField.addActionListener(
    new ActionListener()
    public void actionPerformed(ActionEvent event)
    getThePage(event.getActionCommand());
    container.add(enterField,BorderLayout.NORTH);
    contentsArea = new JEditorPane();
    contentsArea.setEditable(false);
    contentsArea.addHyperlinkListener
    new HyperlinkListener()
    public void hyperlinkUpdate(HyperlinkEvent event)
    if(event.getEventType()==HyperlinkEvent.EventType.ACTIVATED)
    getThePage(event.getURL().toString());
    container.add(new JScrollPane(contentsArea), BorderLayout.CENTER);
    setSize(400,300);
    setVisible(true);
    //load document;change mouse cursor to indicate status
    private void getThePage(String location)
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    try
    contentsArea.setPage(location);
    enterField.setText(location);
    catch(IOException io)
    JOptionPane.showMessageDialog(this,"ERROR retrieving specified URL","Bad URL",JOptionPane.ERROR_MESSAGE);
    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    public static void main(String args[])
    Browser application =new Browser();
    application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    Hello Fixxer, what did you find out from sprint?
    Nurse-Berry
    Follow NurseBerry08 on Twitter

  • Web browser out of memory

    Hi, i'm having problems running an app i've deisgned.
    It is a simple web browser but somtimes i get the lang.outOfMemoryError when i try to open huge pages such as the java api for exemple.
    I've worked on this buf for about 10 hours and even if my app is now running faster and the code looks easy to understand, i still have this problem.
    Here is the code:
    import java.awt.*;
    import java.net.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class Connexion
    extends JPanel {
    private JEditorPane jep;
    private int type;
    private URL url;
    Connexion(String urlString) {
    super();
    jep = new JEditorPane();
    try{url = new URL(urlString);}catch(Exception e){}
    openURL(urlString);
    jep.setEditable(false);
    jep.setContentType("text/html");
    setBackground(Color.white);
    add(jep);
    jep.addHyperlinkListener(new LinkActivator());
    //Permet de faire un "flush" de la m�moire pour afficher les pages importantes
    System.gc();
    //M�thode d'ouverture de l'url ou de modification de l'url pour ouverture
    private void openURL(String urlString) {
    type = 1;
    try {
    url = new URL(urlString);
    jep.setPage(url);/*
    catch (Exception e1) {
    try {
    url = new URL("http://" + urlString);
    jep.setPage(url);
    catch (Exception e2) {
    try {
    url = new URL("http://www." + urlString);
    jep.setPage(url);
    catch (Exception e3) {
    try {
    type = 2;
    url = new URL("file:" + urlString);
    jep.setPage(url);
    catch (Exception e4) {
    try {
    type = 3;
    url = new URL("file:" + System.getProperty("user.dir") +
    System.getProperty("file.separator") +
    "introuvable.htm");
    jep.setPage(url);*/
    catch (Exception ex) {}
    //Permet de faire un flush de la m�moire pour afficher les pages importantes
    System.gc();
    //Retourne l'URL de connexion
    public URL getUrl() {
    return url;
    //Retourne le type de fichier (html ou file)
    public int getType() {
    return type;
    class LinkActivator
    implements HyperlinkListener {
    public void hyperlinkUpdate(HyperlinkEvent he) {
    HyperlinkEvent.EventType type = he.getEventType();
    if (type == HyperlinkEvent.EventType.ENTERED)
    jep.setCursor(
    Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    else if (type == HyperlinkEvent.EventType.EXITED)
    jep.setCursor(Cursor.getDefaultCursor());
    else if (type == HyperlinkEvent.EventType.ACTIVATED)
    openURL(he.getURL().toExternalForm());
    There's too much System.gc() but i think it can improve performance. am I wrong?
    Oh, by the way, i'm french so my comments are in french.
    I hope my english isn't too wrong.
    Please help.
    Thank you by advance.

    oups, sorry about that.
    Here is the formatted code
    import java.awt.*;
    import java.net.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class Connexion
        extends JPanel {
      private JEditorPane jep;
      private int type;
      private URL url;
      Connexion(String urlString) {
        super();
        jep = new JEditorPane();
        try{url = new URL(urlString);}catch(Exception e){}
        openURL(urlString);
        jep.setEditable(false);
        jep.setContentType("text/html");
        setBackground(Color.white);
        add(jep);
        jep.addHyperlinkListener(new LinkActivator());
        //Permet de faire un "flush" de la m�moire pour afficher les pages importantes
        System.gc();
      //M�thode d'ouverture de l'url ou de modification de l'url pour ouverture
      private void openURL(String urlString) {
        type = 1;
        try {
          url = new URL(urlString);
          jep.setPage(url);/*
        catch (Exception e1) {
          try {
            url = new URL("http://" + urlString);
            jep.setPage(url);
          catch (Exception e2) {
            try {
              url = new URL("http://www." + urlString);
              jep.setPage(url);
            catch (Exception e3) {
              try {
                type = 2;
                url = new URL("file:" + urlString);
                jep.setPage(url);
              catch (Exception e4) {
                try {
                  type = 3;
                  url = new URL("file:" + System.getProperty("user.dir") +
                                System.getProperty("file.separator") +
                                "introuvable.htm");
                  jep.setPage(url);*/
                catch (Exception ex) {}
        //Permet de faire un flush de la m�moire pour afficher les pages importantes
        System.gc();
      //Retourne l'URL de connexion
      public URL getUrl() {
        return url;
      //Retourne le type de fichier (html ou file)
      public int getType() {
        return type;
      class LinkActivator
          implements HyperlinkListener {
        public void hyperlinkUpdate(HyperlinkEvent he) {
          HyperlinkEvent.EventType type = he.getEventType();
          if (type == HyperlinkEvent.EventType.ENTERED)
            jep.setCursor(
                Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
          else if (type == HyperlinkEvent.EventType.EXITED)
            jep.setCursor(Cursor.getDefaultCursor());
          else if (type == HyperlinkEvent.EventType.ACTIVATED)
            openURL(he.getURL().toExternalForm());
    }In fact i already the xmx command but i 'm looking for another to debug this.
    There must be at least one.
    Don't I do the connexion in a weird way?
    is there any better way to do this???

  • Very slow GUI in web browser application

    Hello,
    I am trying to write a web browser application and I have a problem with the GUI. When the page is being loaded and set on the JEditorPane the GUI becomes very slow (actually it freezes). I don't know if this happens because of my swing implementation or because I am not using threads properly.
    I use the SwingWorker class. I created a worker thread which loads the web page and then sets it to the JEditorPane.
    Could you give me some ideas please? Below are some parts of my code.
    Thank you
    public class BrowserFrame extends javax.swing.JFrame {
        /** Creates new form BrowserFrame */
        public BrowserFrame() {
            initComponents();
            loadUrlsFromHistoryFile();
        private class RetrievePageTask extends SwingWorker<Void, URL> {
            private String address = null;
            RetrievePageTask(String address) {
                this.address = address;
                pageLoadProgressBar.setIndeterminate(true);
            protected Void doInBackground() {
                URL url = null;
                try {
                    url = new URL(address);
                    publish(url);
                catch(MalformedURLException exc) {
                    System.out.println(exc);
                catch(IOException exc) {
                    System.out.println(exc);
                return null;
            protected void process(List<URL> url) {
                try {
                    pageEditorPane.setPage(url.get(url.size() - 1));
                catch(IOException exc) {
                    System.out.println(exc);
                String url_str = url.get(url.size() - 1).toString();
                addressComboBox.setSelectedItem(url_str);
                addUrlToAddressComboBox(url_str);
        private void addressComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {                                                
            // Get the affected item
            Object item = evt.getItem();
            if(evt.getStateChange() == java.awt.event.ItemEvent.SELECTED) {
                // Item was just selected
                if(item.toString().equalsIgnoreCase(""))
                    return;
                RetrievePageTask retrievePageTask = new RetrievePageTask(item.toString());
                retrievePageTask.execute();
            else if(evt.getStateChange() == java.awt.event.ItemEvent.DESELECTED) {
                // Item is no longer selected
                System.out.println("\nItem: " + item + " is no longer selected");           
        private void addressComboBoxActionPerformed(java.awt.event.ActionEvent evt) {                                               
            if ("comboBoxEdited".equals(evt.getActionCommand())) {
                // User has typed in a string; only possible with an editable combobox
                goButtonActionPerformed(evt);
            else if ("comboBoxChanged".equals(evt.getActionCommand())) {
                // User has selected an item; it may be the same item
                System.out.println("\nSpot TWO");
        private void goButtonActionPerformed(java.awt.event.ActionEvent evt) {
             RetrievePageTask retrievePageTask = new RetrievePageTask(address);
             retrievePageTask.execute();
        private void pageEditorPaneHyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {                                              
            if(evt.getEventType() == javax.swing.event.HyperlinkEvent.EventType.ACTIVATED) {
                 RetrievePageTask retrievePageTask = new RetrievePageTask(evt.getURL().toString());
                retrievePageTask.execute();
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    BrowserFrame surfRider = new BrowserFrame();
                    surfRider.setVisible(true);
    }

    Now it is all.
    package webbrowser;
    import java.net.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    public class BrowserFrame extends javax.swing.JFrame {
        /** Creates new form BrowserFrame */
        public BrowserFrame() {
            initComponents();
            loadUrlsFromHistoryFile();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
        private void initComponents() {
            addressLabel = new javax.swing.JLabel();
            goButton = new javax.swing.JButton();
            jScrollPane1 = new javax.swing.JScrollPane();
            pageEditorPane = new javax.swing.JEditorPane();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            jButton3 = new javax.swing.JButton();
            homeButton = new javax.swing.JButton();
            refreshButton = new javax.swing.JButton();
            addressComboBox = new javax.swing.JComboBox();
            jLabel1 = new javax.swing.JLabel();
            statusLabel = new javax.swing.JLabel();
            pageLoadProgressBar = new javax.swing.JProgressBar();
            menuBar = new javax.swing.JMenuBar();
            fileMenu = new javax.swing.JMenu();
            openFileMenuItem = new javax.swing.JMenuItem();
            exitMenuItem = new javax.swing.JMenuItem();
            viewMenu = new javax.swing.JMenu();
            historyMenuItem = new javax.swing.JMenuItem();
            pageSourceMenuItem = new javax.swing.JMenuItem();
            toolsMenu = new javax.swing.JMenu();
            preferencesMenuItem = new javax.swing.JMenuItem();
            helpMenu = new javax.swing.JMenu();
            aboutMenuItem = new javax.swing.JMenuItem();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Surf Rider");
            setName("browserFrame");
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    formWindowClosing(evt);
            addressLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
            addressLabel.setText("Address:");
            goButton.setText("GO");
            goButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    goButtonActionPerformed(evt);
            pageEditorPane.setEditable(false);
            pageEditorPane.setContentType("text/html");
            pageEditorPane.addHyperlinkListener(new javax.swing.event.HyperlinkListener() {
                public void hyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {
                    pageEditorPaneHyperlinkUpdate(evt);
            jScrollPane1.setViewportView(pageEditorPane);
            jButton1.setText("Back");
            jButton1.setEnabled(false);
            jButton2.setText("Forth");
            jButton2.setEnabled(false);
            jButton3.setText("Stop");
            jButton3.setEnabled(false);
            homeButton.setText("Home");
            homeButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    homeButtonActionPerformed(evt);
            refreshButton.setText("Refresh");
            refreshButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    refreshButtonActionPerformed(evt);
            addressComboBox.setEditable(true);
            addressComboBox.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt) {
                    addressComboBoxItemStateChanged(evt);
            addressComboBox.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    addressComboBoxActionPerformed(evt);
            jLabel1.setText("Browser status: ");
            statusLabel.setText("Current status");
            pageLoadProgressBar.setBorder(javax.swing.BorderFactory.createEtchedBorder());
            fileMenu.setText("File");
            fileMenu.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    fileMenuActionPerformed(evt);
            openFileMenuItem.setLabel("Open File...");
            openFileMenuItem.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    openFileMenuItemActionPerformed(evt);
            fileMenu.add(openFileMenuItem);
            exitMenuItem.setLabel("Exit");
            fileMenu.add(exitMenuItem);
            menuBar.add(fileMenu);
            viewMenu.setText("View");
            viewMenu.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    viewMenuActionPerformed(evt);
            historyMenuItem.setLabel("History");
            viewMenu.add(historyMenuItem);
            pageSourceMenuItem.setLabel("Page Source");
            viewMenu.add(pageSourceMenuItem);
            menuBar.add(viewMenu);
            toolsMenu.setText("Tools");
            preferencesMenuItem.setLabel("Preferences");
            toolsMenu.add(preferencesMenuItem);
            menuBar.add(toolsMenu);
            helpMenu.setText("Help");
            aboutMenuItem.setLabel("About");
            helpMenu.add(aboutMenuItem);
            menuBar.add(helpMenu);
            setJMenuBar(menuBar);
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                    .add(jButton1)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(jButton2)
                    .add(6, 6, 6)
                    .add(refreshButton)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(jButton3)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(homeButton)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(addressLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 56, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(addressComboBox, 0, 568, Short.MAX_VALUE)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(goButton))
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 1008, Short.MAX_VALUE)
                .add(layout.createSequentialGroup()
                    .addContainerGap()
                    .add(jLabel1)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(statusLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 339, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 470, Short.MAX_VALUE)
                    .add(pageLoadProgressBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            layout.setVerticalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .addContainerGap()
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(goButton)
                        .add(jButton1)
                        .add(jButton2)
                        .add(homeButton)
                        .add(jButton3)
                        .add(refreshButton)
                        .add(addressLabel)
                        .add(addressComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 601, Short.MAX_VALUE)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel1)
                            .add(statusLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(pageLoadProgressBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
            java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
            setBounds((screenSize.width-1016)/2, (screenSize.height-724)/2, 1016, 724);
        }// </editor-fold>                       
        private class RetrievePageTask extends SwingWorker<Void, URL> {
            private String address = null;
            RetrievePageTask(String address) {
                this.address = address;
                pageLoadProgressBar.setIndeterminate(true);
            public String getAddress() {
                return address;
            public void setAddress(String newAddress) {
                address = newAddress;
            protected Void doInBackground() {
                URL url = null;
                try {
                    url = new URL(address);
                    publish(url);
                catch(MalformedURLException exc) {
                    System.out.println(exc);
                catch(IOException exc) {
                    System.out.println(exc);
                return null;
            protected void process(List<URL> url) {
                try {
                    System.out.println("\nBefore setting the editorPane");
                    pageEditorPane.setPage(url.get(url.size() - 1));
                catch(IOException exc) {
                    System.out.println(exc);
                String url_str = url.get(url.size() - 1).toString();
                url_str = url_str.toLowerCase(); // URL string is turned in lower case
                addressComboBox.setSelectedItem(url_str);
                addUrlToAddressComboBox(url_str);
                pageLoadProgressBar.setIndeterminate(false);
        private void openFileMenuItemActionPerformed(java.awt.event.ActionEvent evt) {                                                
    // TODO add your handling code here:
        private void viewMenuActionPerformed(java.awt.event.ActionEvent evt) {                                        
    // TODO add your handling code here:
        private void fileMenuActionPerformed(java.awt.event.ActionEvent evt) {                                        
    // TODO add your handling code here:
        private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // Action performed when homeButton's Action Listener listens to an event. This
        // event is passed here as a parameter (evt). The selected item of the addressComboBox is
        // set to be the homePage. The browser goes to the home page.
        private void homeButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
            addressComboBox.setSelectedItem(homePage);
        // This method loads the URL history from the history.txt file into the vector and into the
        // addressComboBox.
        private void loadUrlsFromHistoryFile() {
            BufferedReader inputStream = null;
            addressComboBox.setSelectedItem(homePage);
            try {
                inputStream = new BufferedReader(new FileReader("history.txt"));
                String tmp;
                while((tmp = inputStream.readLine()) != null) {
                    // Adding url to history_mem vector
                    historyMem.add(tmp);
                    // Adding url to addressComboBox
                    addressComboBox.addItem(tmp);
            catch(IOException exc) {
                System.out.println(exc);
        private void addressComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {                                                
            // Get the affected item
            Object item = evt.getItem();
            if(evt.getStateChange() == java.awt.event.ItemEvent.SELECTED) {
                // Item was just selected
                System.out.println("\nItem: " + item + " was just selected");
                if(item.toString().equalsIgnoreCase(""))
                    return;
                RetrievePageTask retrievePageTask = new RetrievePageTask(item.toString());
                retrievePageTask.execute();
            else if(evt.getStateChange() == java.awt.event.ItemEvent.DESELECTED) {
                // Item is no longer selected
                System.out.println("\nItem: " + item + " is no longer selected");           
        // Action performed when an event occurs in the addressComboBox (eg Pressing enter
        // after typing the address).
        private void addressComboBoxActionPerformed(java.awt.event.ActionEvent evt) {                                               
            if ("comboBoxEdited".equals(evt.getActionCommand())) {
                // User has typed in a string; only possible with an editable combobox
                goButtonActionPerformed(evt);
            else if ("comboBoxChanged".equals(evt.getActionCommand())) {
                // User has selected an item; it may be the same item
        // Action performed when goButton's Action Listener listens to an event. This
        // event is passed here as a parameter (evt). When a valid URL is inserted, the
        // pageEditorPane is set to that URL.
        private void goButtonActionPerformed(java.awt.event.ActionEvent evt) {                                        
            // 6 spaces added to the address. This is done for control reasons. Below we
            // use substring which causes exception when those spaces do not exist.
            String address = addressComboBox.getSelectedItem() + "      ";
            if(addressComboBox.getSelectedItem() == null || address.equalsIgnoreCase("      ") || address.equalsIgnoreCase("http://      ")) {
                JOptionPane.showMessageDialog(null, "No address specified.", "No address", javax.swing.JOptionPane.ERROR_MESSAGE);
            else {
                if(!address.substring(0, 7).equalsIgnoreCase("http://"))
                    address = "http://" + address;
                    RetrievePageTask retrievePageTask = new RetrievePageTask(address);
                    retrievePageTask.execute();
        // Action performed when closing the form window
        private void formWindowClosing(java.awt.event.WindowEvent evt) {                                  
            try {
                addUrlsToHistoryFile(historyMem);
            catch(IOException exc) {
                System.out.println(exc);
        /* This method is used to handle the case in which the user clicks on a hyperlink.
         In this case the pageEditorPane must present the contents of the URL that was
         clicked. This URL is retrieved from the evt object (which is a parameter to this
         method) with the method getURL().
        private void pageEditorPaneHyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {                                              
            if(evt.getEventType() == javax.swing.event.HyperlinkEvent.EventType.ACTIVATED) {
                 RetrievePageTask retrievePageTask = new RetrievePageTask(evt.getURL().toString());
                retrievePageTask.execute();
        // This method adds the visited URLs to the addressComboBox's item list. It takes as a
        // parameter the URL which is going to be added. If the URL is already in the list, then
        // it is not added again.
        private void addUrlToAddressComboBox(String url_str) {
            // number of items in the combo box's list
            int itemCount = addressComboBox.getItemCount();
            for(int i = 0; i < itemCount; i++) {
                if(url_str.equalsIgnoreCase((String)addressComboBox.getItemAt(i)))
                    return;
            addressComboBox.addItem(url_str);
            historyMem.add(url_str);
        // This method adds the visited URLs to the history file. It takes as a parameter the URL
        // which is going to be added.
        private void addUrlsToHistoryFile(Vector url_history) throws IOException {
            PrintWriter outputStream = null;
            try {
                outputStream = new PrintWriter(new FileWriter("history.txt"));
                for(int i = 0; i < url_history.size(); i++)
                    outputStream.println((String)url_history.get(i));
            finally {
                if(outputStream != null) {
                    outputStream.close();
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    BrowserFrame surfRider = new BrowserFrame();
                    surfRider.setVisible(true);
        // Variables declaration - do not modify                    
        private javax.swing.JMenuItem aboutMenuItem;
        private javax.swing.JComboBox addressComboBox;
        private javax.swing.JLabel addressLabel;
        private javax.swing.JMenuItem exitMenuItem;
        private javax.swing.JMenu fileMenu;
        private javax.swing.JButton goButton;
        private javax.swing.JMenu helpMenu;
        private javax.swing.JMenuItem historyMenuItem;
        private javax.swing.JButton homeButton;
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JButton jButton3;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JMenuBar menuBar;
        private javax.swing.JMenuItem openFileMenuItem;
        private javax.swing.JEditorPane pageEditorPane;
        private javax.swing.JProgressBar pageLoadProgressBar;
        private javax.swing.JMenuItem pageSourceMenuItem;
        private javax.swing.JMenuItem preferencesMenuItem;
        private javax.swing.JButton refreshButton;
        private javax.swing.JLabel statusLabel;
        private javax.swing.JMenu toolsMenu;
        private javax.swing.JMenu viewMenu;
        // End of variables declaration                  
        // Variables decleration - able to modify
        private Vector<String> historyMem = new Vector<String>();
        private String homePage = "http://www.kaissa.gr";
        // End of variables decleration
        // PUBLIC METHODS
        // Get and Set methods for the private variables declared above
        public Vector getHistoryMem() {
            return historyMem;
        public void setHistoryMem(Vector<String> newHM) {
            historyMem = newHM;
        public String getHomePage() {
            return homePage;
        public void setHomePage(String newHP) {
            homePage = newHP;
    }

  • Running jave apps in web browser

    Hi,
    I'm (very obviously) new to java.
    Longer term I'm looking to develop a distributed application using java. I recently saw a java app that ran in a clients web browser. I assumed that the browser was using java applets, it wasn't. The web page I was looking at clearly had functionality on it that was well beyond that which could be produced by an html page.
    I was told by the person showing me the web page that when the user hit the URL the system would download and install "jar" files if they weren't already installed and the application would run.
    The page had on it a table (datagrid) which could be sorted by clicking on any of the table headings.
    Being new to java I'm unsure what this technology is, if it is not an applet, and how it works. Is anyone out there able to give me a brief high level description of what particular part of the java technology this is (does it require J2SE or J2EE).
    Many thanks...

    1) The "grid" is a JTable component, which is available in applets, providing the plug-in/JRE is of a more recent (1.2+) vintage.
    2) Applets are not HTML - they're little Java programs, which means they can use Swing, which is a much richer UI environment than any HTML page (including DHTML). See #1
    3) Applets are embedded in HTML pages, so they kinda look like they're part of the page, just like using a TABLE tag.
    4) Current JRE/plug-ins cache the applet JAR files, so it's easier to start next time you run across that page.
    5) Web Start is another distribution option, wherein the JRE/plug-in is used to retrieve and update "fat" (stand-alone) applications via a web site, but the browser is not required to run the application. The only time the browser is involved is on the initial download of the application.
    6) J2SE downloads include Web Start.
    Methinks you'd be better off studying and understanding the Java technologies better before you decide you're going to use it...

  • 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).

  • Web Browser program

    Hi guys(girls),
    I am trying to make a program that is a basic web browser what i need to know is what classes i need to use to load a web site up.
    For example i want to type a url in a text field then hit a button then it is loaded on to the frame
    note i want this in a application not a applet i have done a little looking on the sun site but couldnt find any thing that was useful

    Here are a few classes to start with:
    java.net.URL
    java.net.HttpURLConnection
    javax.swing.JTextPane
    You could also look for Sun's HotJava browser, maybe it's open source already ...

  • Web browser inside web flash applications

    Dear all, I need  web browser inside my web flash application.. i use Flash Builder.. i dont find a any straight way to do this.. i saw examples using iFrames.. cud anyone help with how to do this in the best way..?

    JEditorPane (http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JEditorPane.html)
    offers some support for displaying HTML.

  • 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.

  • Web Browser.....Code is inside...but clarify few things!

    HI All,
    this is pilot ..sorry to bother u again but this time its kinda important
    here is my program for a web browser--
    now i wanna know a few things HyperlinkListener just not support javascript nor does it support flash ...thats 2 and i wanna know wht else restrictions that are in this simple browser....
    and can u tell me how can i make this browser more faster and i wanna add a JProgressBar to it and i have no clue...please help/
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    import javax.swing.JButton;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JEditorPane;
    import javax.swing.JLabel;
    import java.io.IOException;
    import java.awt.GridBagLayout;
    import java.awt.GridBagConstraints;
    import java.awt.BorderLayout;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import javax.swing.UIManager;
    import javax.swing.JEditorPane;
    import javax.swing.event.HyperlinkListener;
    import javax.swing.event.HyperlinkEvent;
    import javax.swing.JOptionPane;
    public class Browser implements ActionListener
         JTextField t1;
         JLabel l1;
         JButton b1;
         GridBagLayout gbl;
         GridBagConstraints gbc;
         JPanel p;
         JFrame frame;
         JScrollPane scrollPane;
         JEditorPane jep;
         static String initialPage;
    public Browser()
         //JFrame.setDefaultLookAndFeelDecorated(true);
         /*try
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
         catch(Exception e)
             e.printStackTrace();
         frame=new JFrame("Simple Web Browser");
         gbl=new GridBagLayout();
         gbc=new GridBagConstraints();
         p=new JPanel();
         p.setLayout(gbl);
         jep = new JEditorPane();
         t1=new JTextField();
         b1=new JButton("Check it out!");
         b1.addActionListener(this);
         frame.getRootPane().setDefaultButton(b1);
         l1=new JLabel("Address");
         gbc.anchor=GridBagConstraints.NORTHEAST;
         gbc.fill=GridBagConstraints.HORIZONTAL;
         gbc.gridx=0;
         gbc.gridy=0;
         gbc.weightx=0.0;
         gbl.setConstraints(l1,gbc);
         p.add(l1);
         gbc.anchor=GridBagConstraints.NORTHEAST;
         gbc.gridx=1;
         gbc.gridy=0;
         gbc.weightx=1.0;
         gbl.setConstraints(t1,gbc);
         p.add(t1);
         gbc.anchor=GridBagConstraints.NORTHWEST;
         gbc.gridx=2;
         gbc.gridy=0;
         gbc.weightx=0.0;
         gbl.setConstraints(b1,gbc);
         p.add(b1);
        scrollPane = new JScrollPane(jep);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(p,BorderLayout.NORTH);
         frame.getContentPane().add(scrollPane);
        frame.setSize(1000,700);
        frame.setVisible(true);
    public void actionPerformed(ActionEvent e)
              initialPage=t1.getText();
              char a=initialPage.charAt(0);
              char b=initialPage.charAt(1);
              char c=initialPage.charAt(2);
              char d=initialPage.charAt(3);
              char ea=initialPage.charAt(4);
              char f=initialPage.charAt(5);
              char g=initialPage.charAt(6);
              if((a=='h')&&(b=='t')&&(c=='t')&&(d=='p')&&(ea==':')&&(f=='/')&&(g=='/'))
                   initialPage=t1.getText();
              else
                   initialPage="http://"+initialPage;
              jep.setEditable(false);
              jep.addHyperlinkListener(new second(jep));
             try
               jep.setPage(initialPage);
             catch (IOException ae)
                JOptionPane.showMessageDialog(frame,new String("Error: "+ae));
    public static void main(String[] args)
              new SimpleWebBrowser();
    class second implements HyperlinkListener
      private JEditorPane pane;
      public second(JEditorPane pane)
        this.pane = pane;
    public void hyperlinkUpdate(HyperlinkEvent evt)
       if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
          try
           pane.setPage(evt.getURL());
         catch (Exception e){}
      }}}

    Broken Browser excuse me/...check this out ---> run it and tell me if the code is broken...
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    import javax.swing.JButton;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JEditorPane;
    import javax.swing.JLabel;
    import java.io.IOException;
    import java.awt.GridBagLayout;
    import java.awt.GridBagConstraints;
    import java.awt.BorderLayout;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import javax.swing.UIManager;
    import javax.swing.JEditorPane;
    import javax.swing.event.HyperlinkListener;
    import javax.swing.event.HyperlinkEvent;
    import javax.swing.JOptionPane;
    public class Browser implements ActionListener
         JTextField t1;
         JLabel l1;
         JButton b1;
         GridBagLayout gbl;
         GridBagConstraints gbc;
         JPanel p;
         JFrame frame;
         JScrollPane scrollPane;
         JEditorPane jep;
         static String initialPage;
    public Browser()
         //JFrame.setDefaultLookAndFeelDecorated(true);
         /*try
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
         catch(Exception e)
             e.printStackTrace();
         frame=new JFrame("Simple Web Browser");
         gbl=new GridBagLayout();
         gbc=new GridBagConstraints();
         p=new JPanel();
         p.setLayout(gbl);
         jep = new JEditorPane();
         t1=new JTextField();
         b1=new JButton("Check it out!");
         b1.addActionListener(this);
         frame.getRootPane().setDefaultButton(b1);
         l1=new JLabel("Address");
         gbc.anchor=GridBagConstraints.NORTHEAST;
         gbc.fill=GridBagConstraints.HORIZONTAL;
         gbc.gridx=0;
         gbc.gridy=0;
         gbc.weightx=0.0;
         gbl.setConstraints(l1,gbc);
         p.add(l1);
         gbc.anchor=GridBagConstraints.NORTHEAST;
         gbc.gridx=1;
         gbc.gridy=0;
         gbc.weightx=1.0;
         gbl.setConstraints(t1,gbc);
         p.add(t1);
         gbc.anchor=GridBagConstraints.NORTHWEST;
         gbc.gridx=2;
         gbc.gridy=0;
         gbc.weightx=0.0;
         gbl.setConstraints(b1,gbc);
         p.add(b1);
        scrollPane = new JScrollPane(jep);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(p,BorderLayout.NORTH);
         frame.getContentPane().add(scrollPane);
        frame.setSize(1000,700);
        frame.setVisible(true);
    public void actionPerformed(ActionEvent e)
              initialPage=t1.getText();
              char a=initialPage.charAt(0);
              char b=initialPage.charAt(1);
              char c=initialPage.charAt(2);
              char d=initialPage.charAt(3);
              char ea=initialPage.charAt(4);
              char f=initialPage.charAt(5);
              char g=initialPage.charAt(6);
              if((a=='h')&&(b=='t')&&(c=='t')&&(d=='p')&&(ea==':')&&(f=='/')&&(g=='/'))
                   initialPage=t1.getText();
              else
                   initialPage="http://"+initialPage;
              jep.setEditable(false);
              jep.addHyperlinkListener(new second(jep));
             try
               jep.setPage(initialPage);
             catch (IOException ae)
                JOptionPane.showMessageDialog(frame,new String("Error: "+ae));
    public static void main(String[] args)
              new Browser();
    class second implements HyperlinkListener
      private JEditorPane pane;
      public second(JEditorPane pane)
        this.pane = pane;
    public void hyperlinkUpdate(HyperlinkEvent evt)
       if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
          try
           pane.setPage(evt.getURL());
         catch (Exception e){}
      }}}

  • Web Browser using GUI

    Hello, I have make a Web Browser using Swing/AWT, I've done the basic Web Browser, my assignment asks for addtional functionality like Bookmarks, and history. I can't post all the code, but here's what i've done for both.
         * History menu and add file menu items
        private void makeHistoryMenu()
            historyItem = new JMenuItem("History");
            historyItem.setBackground(Color.white);
            historyItem.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                      //Add url to history;
           // historyMenu.add(location);
    // Bookmark button
            bookmarkButton = new JButton("Bookmark");
            bookmarkButton.setToolTipText("Bookmark");
            bookmarkButton.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent evt)
                    URL url;
                    try
                        String location = locationInput.getText();
                        location = "http://" + location;
                        historyArray.add(location); // Do I need an arraylist to store the entries??
                    catch (Exception e)
                        return;
            });it doesn't show the the bookmarks or the history
    Thanks

    you must add the button to the Component where you want to show it
    (or the historyItem to the JMenu)
    e.g.:
    JFrame frame = new JFrame();
    JButton historyButton = new JButton("History);
    frame.add(historyButton);
    frame.setVisible(true);
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Web Browser Plugin

    I have an applet that uses Swing, but when I try to run it on my web browser, I get a ClassNotFoundException
    for JTextField.
    What should I do about that?

    Did you install JRE? You may need Java plug-in.

Maybe you are looking for

  • Unable to upload Transport Package in portal

    Hi Previously i have transported .epa file(Trnasport Package) from dev to acc, it worked fine there.now when iam trying to upload the same in qas portal its getting error like "could not upload file" .can any one assist me with the solution

  • Inspection lot, goods movements not possible!

    Hello dear SAP Gurus and friends, I am trying to do a stock transfer from Quality to Unrestricted in QA32, but SAP shows error "Please fill delivery note!". I have checked the Purchase Order and Delivery Note is filled! Can you please help? Thanks in

  • Fault policy is not working in BPEL Process

    Hi All, I am handling A Fault (remoteFault) thrown by Throw Activity in BPEL process using Fault policies. For this I have Created two xml file called fault-policies.xml and fault-bindings.xml and kept them in the same directory as in Composite.xml f

  • Sap smartforms: complex section

    i am new to sap abap.i was trying for smartform program.I got one link.. there they have used complex section tab in smartforms which i am unable to find in ECC 6.0. please provide me the what is the alternative method to use the complex section in E

  • Format of response from distributed form

    Hi guys, I have been working with a trial of Acrobat X Pro and Livecycle ES II, to determine if we can use it effectively to replace paper forms in our workplace. We have also recently deployed Alfresco, an open source CMS, which is very tightly inte