greetings, one and all!
Today, we will be learning about a couple of really neat components that can make your programs that much more legit acting and looking. The first one is a JToolbar, and it is exactly like it sounds: it functions in much the same way as the toolbar you find in the browser you're using right this second. The second is a JToggleButton, which can be used to turn things on and off.
When we're done playing with these two new additions, you will need to do the usual routine of applying what you've learned to something else you already knew, AND sending your new program by email, AND posting a discussion about it. Plus, after you're done with that, you will get to apply what you've learned to something that we haven't covered in class, which I know many of you are doing already anyhow. Btw, if there is still some interest by any of you in leading the class on a particular topic of your choosing, please let me know.
OK, lets get going: download the Java file and the image files found here:
http://www.box.net/shared/zkrrerzdfx
and put 'em all in a separate directory inside your main Java folder
The first step to take after opeing this program in TextPad is to add a JToolbar to it. Add this to your declarations:
JToolBar Utool;
and then add it to memory in your constructor like so:
Utool = new JToolBar("Standard ToolBar, Inc.",JToolBar.HORIZONTAL );
Utool.setFloatable(true);
and then add this line:
ToolBox.add(Utool);
just above this line:
Hammer.setVisible(true);
this gets you a toolbar that starts horizontal and can be dragged around (more on that later)
BUT, if you compile and run your program now, you won't see very much: you have to put some JButtons on this thing first! So add this to your declarations:
JButton Smile, Stop, BraveHeart;
and then add this first JButton to your JToolbar, like so:
Smile = new JButton(new ImageIcon("mrHappy.jpg") );
Smile.addActionListener(this);
Utool.add(Smile);
Save, compile, then run your program. What you should have now is a MUCH more visible JToolbar which has one button in it. AND, you can drag that JToolbar around all over the place. Pretty neat, huh?
Now, add those other two JButtons to your Jtoolbar, then lets get to the next phase
Cheers,
Uncle Paulie
Tuesday, April 7, 2009
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment