Greetings, fellow JavaNoidz!
In keeping with our ongoing exploration of Java Swing, today we will be looking at how to make a program that functions as a tabbed web browser. It's a little crude, but it will do to introduce you to several components we haven't explored yet, re-aquaint you with some items we haven't used in a while, and in general, do something both useful and k3wl.
To begin, download the program found at this address:
http://www.box.net/shared/pdhemt4r06
When you start it up, it won't look like much: a JFrame with a Container, a JPanel, which is like every Panel we've used before, etc etc. I've written in a lot of the declarations already, too.
The first thing we're going to do is to create a new component called a "JTabbedPane". It is exactly what it sounds like: a container with a little tab on top; it looks a lot like Firefox
Add this component to your constructor:
Tabitha= new JTabbedPane( );
Tabitha.setBounds(0,35,980,790);
ProvingGround.add(Tabitha);
next, add this method call inside your constructor...
makeTab( ); //set first tab by making method call
it'll call a method that will load a JEditorPane into the JTabbedPane we just created:
Since we're calling a method, we should make sure it exists too! Create this method just after your constructor:
private void makeTab( )
{
System.out.println("What are we gonna do tonight?");
//setup JEditorPane using try catch
try {
newWeb = new JEditorPane(StartPage);
newWeb.setEditable(false);
newWeb.setBounds(10,50,850,720);
Tabitha.add("Page " + pageNumber ,newWeb);
} //end try
catch(IOException ioe)
{
System.out.println("try and take over the world!");
} //end catch
pageNumber++; //increment int by one
} //end makeTab method
What this method does is to
A) create a JEditorPane
B) add it to a new Tab that is created which
C) is named after a String called "Page" plus an integer value which gets
"bumped up" by one at the end of the method
D) the tab includes the new JEditorPane object called newWeb
Cheers,
Uncle Paulie
Wednesday, April 1, 2009
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment