Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: How to give URL connecton to this.

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to give URL connecton to this.

    Need to know how to give URL Connection to this? Can some one help me out with this?

    import java.awt.*;

    import java.awt.event.*;
    import java.util.*;
    import java.net.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.event.*;

    public class WebBrowser
    {
    public static void main(String [] args)
    {
    JFrame frame = new EditorPaneFrame();
    frame.show();
    }
    }
    class EditorPaneFrame extends JFrame
    {

    private JTextField url;
    private JCheckBox editable;
    private JButton loadButton;
    private JButton backButton;
    private JEditorPane editorPane;
    private Stack urlStack = new Stack();


    public EditorPaneFrame()
    {
    setTitle("Java Web Browser");
    setSize(600,400);
    addWindowListener(new WindowAdapter()
    {
    public void windowClosing(WindowEvent e)
    {
    System.exit(0);
    }
    } );

    // set up text field and load button for typing in URL

    url = new JTextField(30);

    loadButton = new JButton("Load");
    loadButton.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent event)
    {
    try
    {
    // remember URL for back button
    urlStack.push(url.getText());
    editorPane.setPage(url.getText());
    }
    catch(Exception e)
    {
    editorPane.setText("Error: " +e);
    }
    }
    });

    // set up back button and button action

    backButton = new JButton("Back");
    backButton.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent event)
    {
    if(urlStack.size()<=1) return;
    try
    {
    urlStack.pop();
    String urlString = (String)urlStack.peek();
    url.setText(urlString);
    editorPane.setPage(urlString);
    }
    catch(IOException e)
    {
    editorPane.setText("Error : " +e);
    }
    }
    });

    editorPane = new JEditorPane();
    editorPane.setEditable(false);
    editorPane.addHyperlinkListener(new HyperlinkListener()
    {
    public void hyperlinkUpdate(HyperlinkEvent event)
    {
    if(event.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
    {
    try
    {
    urlStack.push(event.getURL().toString());
    url.setText(event.getURL().toString());

    editorPane.setPage(event.getURL());
    }
    catch(IOException e)
    {
    editorPane.setText("Error: " + e);
    }
    }
    }
    });

    editable = new JCheckBox();
    editable.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent event)
    {
    editorPane.setEditable(editable.isSelected());
    }
    });

    Container contentPane = getContentPane();
    contentPane.add(new JScrollPane(editorPane), "Center");

    JPanel panel = new JPanel();
    panel.add(new JLabel("URL"));
    panel.add(url);
    panel.add(loadButton);
    panel.add(backButton);
    panel.add(new JLabel("Editable"));
    panel.add(editable);

    contentPane.add(panel,"South");
    }

    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to give URL connecton to this.

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    how to give URL Connection
    Can you explain what you are trying to do?
    Are you talking about the URLConnection class?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to give URL connecton to this.

    Yes the URLConnection Class.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to give URL connecton to this.

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    Can you explain what problems you are having doing that?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Could someone give me some insight as to how to do this?
    By blobman23 in forum What's Wrong With My Code?
    Replies: 13
    Last Post: November 11th, 2013, 08:46 PM
  2. How do we give a color to a disabled url label which extends a jlabel
    By oberoi06 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 16th, 2013, 11:15 AM
  3. Problems with Jtable.setModel() with Db connecton
    By justyStepi in forum JDBC & Databases
    Replies: 0
    Last Post: September 18th, 2012, 07:22 AM
  4. Url Image stream? Getting an Image url.
    By turtlemaster in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: June 30th, 2012, 09:43 AM