Wednesday, April 1, 2009

Tues April 1: Java Swing Tabbed Browsing, part Three

So now we can make tabs -- and LOTS of 'em!-- but they all display the same darned website! How's about we wanna choose our own site?



No problem-o... here's the way I did it. Perhaps you might have done it differently. This product sold by weight, not by volume...some settling of contents may have occurred during shipping :-)













Add this to your declarations section:
JTextField WhereTo;

Add these two components to your constructor:

Brain = new JButton("Go There");
Brain.setBounds(160,0,130,20);
Brain.addActionListener(this);
ButtonsAndText.add(Brain);

WhereTo = new JTextField(StartPage, 20); //starting page plus # of columns
WhereTo.setBounds(0,0,200,20);
WhereTo.addActionListener(this);
ButtonsAndText.add(WhereTo);

Add this “else if” to your actionPerformed:
else if (e.getSource() == Brain)
{
changePage( ); // make method call
}


Add this method just below the “makeTab( )” method
private void changePage( )
{
System.out.println("are you pondering what I'm pondering?");
StartPage = WhereTo.getText(); //set to addy in JTextField
makeTab( ); //call the other method, create new tab with new address
}//end method changePage

No comments:

Post a Comment