-2

I'm currently working on a Java Program using JFrames. I'm supposed to create a URLFrame in which I can input a web address and ask the program to fetch it and display it in the Frame. So far I am stuck and would like input on if I'm on the right track and where to go from here:

import javax.swing.*;
public class URLFrame extends JFrame {

    private JPanel panel;
    private JLabel messagelLabel;
    private JTextField enterAddress;
    private JButton fetchButton;
    private JTextArea displayPage;
    private JButton displayScriptCount;
    private JButton writePage;
    private JTextArea checkStatus;

    public URLFrame(){

        setTitle("Enter Address");
        setSize(WINDOW_WIDTH, WINDOW HEIGHT);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        buildPanel();
        add(panel);
        setVisible(true);
    }
}
Brian
  • 14,610
  • 7
  • 35
  • 43

2 Answers2

0

Sounds like you are looking for something along these lines

Pure Java HTML viewer/renderer for use in a Scrollable pane or http://www.teamdev.com/jxbrowser

Due to the vagueness of the question, that is what I can think up. Both sources have adequate guidance on setups directly or indirectly.

EDIT: To use a textfield as an 'address-bar', use this:

String url = jTextField_For_Url_Input.getText();
java.net.URL url_to_connect_to = new java.net.URL(url);
//... whatever needed for implementation

http://www.tutorialspoint.com/java/java_url_processing.htm give a good tutorial to help you learn and you can combine this with the suggestions of the HTML related components to view a rendered copy of HTML content.

Another resource using the JEditorPane is here

Community
  • 1
  • 1
0

Read the section from the Swing tutorial on How to Integrate With the Desktop Class.

You can use the examples there to load a URL into the default browser.

The Swing JEditorPane will display basic HTML. Look at the table of contents from the above link and you will find a section on Text Component Features that might help.

camickr
  • 321,443
  • 19
  • 166
  • 288