OK, now setting colors is all very cool, but it starts me to wondering: isn't the World Wide Web just full of color? It sure looks that way to me. Plus -- and maybe this hasn't been on YOUR mind lately, but I've been thinking about it-- there should be some way in Java to make a webpage viewer, same as in Visual Basic, right? Well of course there is. It's called a JEditorPane. Let's get introduced, shall we?
The first thing you have to do is to add these imports
import java.io.*; //for try catch to make JEditorPane
import java.net.*; //for use with setting new URL for JEditorPane
Creating a JEditorPane is not as simple as it might seem: because you're trying to load a webpage, and the webpage might not be there, you have to do it in a "try catch", which is sort of like an if else statement.
Next step, add these declarations:
JEditorPane Webapalooza;
String StartPage = "http://www.google.com";
And add this to your constructor, just below where you added the "Skittles" button:
//setup JEditorPane using try catch
try {
Webapalooza = new JEditorPane(StartPage);
Webapalooza.setEditable(false); //this component can be used to edit, but not now
Webapalooza.setBounds(0,50,780,550);
ProvingGround.add(Webapalooza);
} //end try
catch(IOException ioe)
{ } //end empty catch
Now when you run your program, you should see the webpage for Google displayed in the JEditorPane
Tuesday, March 31, 2009
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment