Hello Everyone,
I'm wondering if there is an easy way or a not so easy way to interpret HTML to form actual web pages in java? I currently have the HTML input from the web server but now I need to interpret it to create readable web pages... Is there any class or method to do this in java?
Cheers
Interpretting HTML in java to display web pagesAny class to do this?
Page 1 of 1
5 Replies - 2834 Views - Last Post: 15 December 2008 - 09:31 PM
Replies To: Interpretting HTML in java to display web pages
#2
Re: Interpretting HTML in java to display web pages
Posted 15 December 2008 - 03:41 PM
This should get you started: http://www.codeguru....icles/451.shtml
#3
Re: Interpretting HTML in java to display web pages
Posted 15 December 2008 - 08:44 PM
Ok right on ya that's what I need... however i'm not sure how to implement it... what part of the code is actually interpretting the html... and is it only JTextPane that can interpret html or can JTextArea do it too? Here is the code william led me to...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class Test
{
public static void main(String args[])
{
JTextPane tp = new JTextPane();
JScrollPane js = new JScrollPane();
js.getViewport().add(tp);
JFrame jf = new JFrame();
jf.getContentPane().add(js);
jf.pack();
jf.setSize(400,500);
jf.setVisible(true);
try {
URL url = new URL("http://www.google.ca/" );
tp.setPage(url);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
#4
Re: Interpretting HTML in java to display web pages
Posted 15 December 2008 - 08:57 PM
#5
Re: Interpretting HTML in java to display web pages
Posted 15 December 2008 - 09:08 PM
Ok I'm a little confused as to how this works. Is it just setPage that I will need? I'm thinking i'm going to need some other things that I can't seem to figure out. Never did like the sun API documentation for explanations. Here is my code... not sure what i'm doing but it's now throwing a run time error in regards to the setPage call. Also nothing is happening when I press the enter button and i'm not sure why...
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.*;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import java.util.Scanner;
public class MainWindow extends JFrame
{
private JTextField URLBar;
private JButton Back;
private JButton Forward;
private JTextPane Display;
private JButton Enter;
private final int WINDOWHEIGHT = 1200;
private final int WINDOWWIDTH = 700;
private JPanel URLPanel;
private JPanel TextPanel;
private final int ROWS = 35;
private final int COLUMNS = 60;
final int PORT = 80;
private JScrollPane ScrollArea;
//private JProgressBar Progress;
public MainWindow()
{
//set the default size of the window
setSize(WINDOWHEIGHT, WINDOWWIDTH);
//set what happens when user presses the close button
setDefaultCloseOperation(EXIT_ON_CLOSE);
//set the title of the window
setTitle("Unknown");
//set the layout to grid layout for the panel
setLayout(new BorderLayout());
//set the contents of the URL Bar
Back = new JButton(" Back ");
Forward = new JButton("Forward");
URLBar = new JTextField(30);
Enter = new JButton("Enter");
//set the contents of the text area
Display = new JTextPane();
//Progress = new JProgressBar();
//set the text Area to display scroll bars
Display.setLayout(new FlowLayout());
ScrollArea = new JScrollPane(Display);
getContentPane().add(ScrollArea);
//create the panel
URLPanel = new JPanel();
TextPanel = new JPanel();
//add the contents to the panels
URLPanel.add(Back);
URLPanel.add(Forward);
URLPanel.add(URLBar);
URLPanel.add(Enter);
//add the text area to the panel
TextPanel.add(ScrollArea);
//TextPanel.add(Progress);
Enter.addActionListener(new EnterActionListener());
//add the panel to the frame
add(URLPanel, BorderLayout.NORTH);
add(TextPanel, BorderLayout.CENTER);
pack();
setVisible(true);
}
public class EnterActionListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
String Url;
Url = URLBar.getText();
try
{
URL NewUrl = new URL(Url);
//URLConnection NewConnection = NewUrl.openConnection();
Display.setText(Url);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Cannot find the website" +
" ensure that is in the format [url="http://www.google.ca/");"]http://www.google.ca/");[/url]
}
}
}
//Main Method to create the an instance of the browser
public static void main(String[] args) throws IOException
{
new MainWindow();
}
}
This post has been edited by markhazlett9: 15 December 2008 - 09:11 PM
#6
Re: Interpretting HTML in java to display web pages
Posted 15 December 2008 - 09:31 PM
Nevermind... got it... Thanks William! Cheers
This post has been edited by markhazlett9: 15 December 2008 - 10:37 PM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|