Wednesday, June 17, 2009
Wednesday, June 17: and then there was one
Since our purpose is to get absolutely as much done of your finals BEFORE the actual day of the final exam, I thought it best to lead off with what I still lack from each of you. For each item below, if you have the files, please send them ASAP:
A) a group discussion posting about your killer app, what it is intended to do, how you plan to build it, etc. I still need this from James, Ryan C., and Evan...pl;us I blieve that Ryan N. only emailed it to me, so if you could post what you emailed Ryan, that'd be swell
B) "year in review" group posting --> still cannot find one for Ryan C. and Dillon
C) research topic group discussion posting: I still cannot locate one for the following people:
Ryan C, Evan, Dillon
Additionally, I'm having "source citation" troubles with the following people:
EJ, Sean, Thomas
remember, you need to have eight sources listed, directly below your actual discussion post. NOT somewhere else, I don't wanna guess!
D) the actual "killer app" --> so maybe it cannot kill just yet. Maybe it can't maim. Maybe it cannot fold, spindle or mutilate. Perhaps its incapable of breaking the skin. Maybe it cannot even break the skin off a rice pudding. Whatever! Just make sure to send in a copy before the end of the class, by email, with your name and the phrase "killer app" in the subject line. Make sure to actually ATTACH the file please. And be aware, not only can you work on this for the rest of the week, in your spare time and on the day of the actual exam if you feel the need, it's also meant to be thought provoking long after this building goes quiet for the summer.
Th-th-th-that's all, folks!!!!!!
Uncle Paulie
Monday, June 15, 2009
Tuesday June 16: Two days left: what else is there to say?
You have already received instructions for all that you must do to complete your final exam projects before the actual exam day. Considering that that will be THE last day for you, that's actually pretty generous: if we are successful, all we have to do is come in that day and enjoy one last time together before the summer.
Please make sure that you have done everything that needs to be done, posted all group discussions, sent all needed emails, so that then you may work on your "killer apps"
You know what needs to be done. As the Nike commercials say: "JUST DO IT!"
Cheers,
Uncle Paulie
Friday, June 12, 2009
Friday, June 12: a great big TODO list for all of you
Let's get right to the big stuff first, shall we?
A) With only one exception, I cannot seem to find evidence of anyone sending me by email a "choice of topic" -- that's be the topic to do with computer programming that you began at least a week ago-- eight website sources you will be able to cite, a list of facts about your chosen topic, a formal written set of paragraphs, WHICH, along with your wesbite source addresses, you were supposed to have posted as a group discussion.
Since it's more likely that I've overlooked something somehow, here's what I want you to do with that:
POST IT AS A GROUP DISCUSSION RIGHT NOW. PLEASE REFER TO THE BLOG POSTINGS TO SEE WHAT MUST BE INCLUDED. MAKE SURE TO CLEARLY LABEL IT AS YOUR RESEARCH TOPIC. DO NOT POST UNDERNEATH SOMEONE ELSE'S POST.
B) I have been unable to find the "year in review" discussion posting for the following people:
Dylan, Evan, EJ, Ryan C. Guys, get it done, its not possible to get it wrong, unless you don't do it at all, OR you're really cheap on me with how much you write
C) I have received neither an email nor a group discussion posting to do with your "website resources" to do with your killer app from the following people:
James, Ryan C., Evan Please take care of this one way or the other. Refer to the blog posts or to your peers for advice in what I'm asking for here, I've already stated it at least twice.
D) When all is said and done, by the end of this class, I will need you to email me the latest copy of your "killer app". Whatever its state of development, please send me a copy by the end of class. Please put your name and the phrase "killer app" in the subject line
OK, you gotta a lunch block to work in: let's get it done. And yes, start with the easy stuff: why do you think they're in the exam, if not to boost your confidence?
Cheers,
Uncle Paulie
Wednesday, June 10, 2009
Thursday June 11: end game part 4
Today, there are several things which you will need to start "wrapping up". They include the following:
A) You will need to use the email version of your "year in review" and set up a group discussion posting BASED on it. The discussion possting should be labeled with your name plus the phrase "year in review". it should be at least three paragraphs of at least three complete sentences each in length, and it should include all the points you brought up in your rough draft email, which if you will recall, needed at least seven things you remembered about this class
B) You will need to produce another group discussion posting BASED on the email you (theoretically) sent to me back on Monday, June 8. this email not included your choice of a topic to do with computer programming. Recall that the discussion topic was supposed to be on about "some person, company, "killer app",milestone, "day of infamy" etc etc etc in computer programming. " Recall also that you were most recently supposed to have sent me two facts derived from each of the eight website based sources you were supposed to locate as part of this effort.
Sooooooooooooooooooooo....make a discussion posting that's at least the same basic format as the one found in point A) above, but includes ALL the info you gathered and emailed to me the other day
C) The "killer app" email you sent to me as the first part of this exam period project also needs to be posted as a group discussion. make sure you label it as your name, plus the phrase "my killer app"
D) While you're at it, do something to begin creating this app. At some point, I will have you upload or email me a copy of it
Cheers,
Uncle Paulie
Sunday, June 7, 2009
Monday June 8: End game part three
Today, you will be working towards accomplishing three separate objectives:
A) Continue to gather resources towards beginning to create your "killer app" (you can test them out as you will, and see what shakes loose. After all, it's a code class, yes?)
B) You need to expand upon the research topic you chose last week by emailing me at least two facts you have discovered about your topic from EACH of the eight online sources you procured last week. Each fact must be presented in the form of a complete sentence. Make sure your email is labeled with your name and the phrase "my topic facts"
C) "year in review" create a rough draft on the topic of "year in review". All you have to do for this is to email me at least seven different things that stand out in your mind about this class. Whatever you remember the best, the events that stand out the most, particular programs, the teamwork, the weird examples etc etc etc. Just make sure that the subject line of the email includes your name and "rough draft year in review". A complete sentence for each item you recall the best will suffice for now
"the faster we go, the rounder we get"
Uncle Paulie
PS Even if you were not physically here to do this assignment, you are still responsible for it. Most of it can be done without actually even being here. Which begs the question then: why do any of have to get outta bed to come all the way here for then? :-)
Wednesday, June 3, 2009
Wednesday June 3: End game part two
Yesterday, you were asked to describe as well as possible, your idea for a "killer app". Most of you have responded...those of you who have not need to get that done and passed in before the end of today's class. You really don't want to fall behind on this point, especially if you happen to be a sophomore, since I will in all likelihood NOT see you tomorrow due to MCAS
That much being said, today you will need to begin drafting your response to letters B) and C) from yesterday. Let's start with
B) "You've taken your first step into a larger universe"
The point of this is to begin gathering resources that you will need to actually begin trying to realize the vast ambitions you outlined in point A)making a "killer app"
What kind of resources? Well, to begin with, you will need to make a discussion post detailing the individual components you think your "K A" will need.
For example, if you need your program to access a website in some way, well, we've sorta kinda done that, but you might need more information about how to improve that. Ditto if your program needs to be able to read from or write to some files: we've gotten a good start on that, but we've hardly exhausted the possibilities. Moreover, we've never even touched on items like connecting to databases or producing HTML documents "on the fly"
Once you've listed stuff you think you'll need, you'll need to go out and scour the Web looking for people and places that might have something like what you're looking for. AND, you will need to keep a record of those websitess URLs AND a succint tag for each one saying what that site is good for. Trsut me, don't hold this stuff in your head: you'll end up losing your hair. Not to mention its a requirement for you to make a second discussion post listing this information
Last for point B) you will need to start trying to make use of the resources you've found. If there are tutorials or sample code to download, then get crackin'... you have free reign to make use of ANYTHING you can lay your caffeinated little hands upon. let;s see what we can scare up!
OK, now as for point C: each of you will be (eventually) making a discussion post about some person, company, "killer app",milestone, "day of infamy" etc etc etc in computer programming. It goes back a lot further than you think: for example, you could do a discussion about "George Boole". BUT, long before you do the discussion, you have to GATHER RESOURCES. In this case, you need to have on hand at least a bytes worth of credible websites as sources you could cite in the course of your discussion. These sources you will need to email to me, putting your name and "research point C websites" in the subject line
OK, that oughtta be enough exercise for today!
Cheers,
Uncle Paulie
Monday, June 1, 2009
Tuesday June 2: End Game, Part One
Before we begin, allow me to give you a very simple outline of what we will be accomplishing over the next two weeks:
A) What makes a "killer app"? Details to follow quite soon
B) "You've taken your first step into a larger universe" Details to follow
C) not so random research : each of you will be researching a particular topic that has something to do with computer programming. Details to follow
D) "year in review" Details to follow
E) "speak,hands, for me!" Details to follow
In any event, let's get down to what you will be doing today:
The term "killer app" was coined long ago in the 1980s to describe a computer program that was so important and influential to how computers were developing that they crushed all the competition. At one point or another, every computer geek dreams of making their own, just like every politician dreams of becoming President and every dog dreams of waking up in a world where all the cars are slow and they're made of Beggin' Strips.
So here's your chance to dream out loud. Please describe what your killer app would be like, if only you could invent one. Your description must include the following:
1) what general category would this app fall into? Would it be a utility program, something that would help make your computer work better? Would it be some kind of instant messaging or email software? Would it work with databases? Would it be a game of some sort? Would it be used to test network security ("pen testing")?
2) What kind of person would you try to get to use this software? Think about things like age, gender, lifestyle, income bracket, what they do for a living, what their hobbies or interests might be.
3) How would you distribute it? In other words, how would an interested party get a hold of a copy of your software?
4) Would you attempt to patent it and make it propietary, or would you go open source, let the world see how you did it, and try to make money on its usage?
5) For that matter, would you be trying to make money from this, or would that not be a consideration? (Remember, there's no one right answer to this)
6) How would you get this "before the public"? In other words, how do you plan on getting people's attention long enough to TRY your "killer app", bearing in mind the "MTV syndrome"
7) What if someone wanted to buy the rights to this software of yours, what would you do? How would you respond? Again, there is no one right answer to this.
8) Finally, who do you feel would be the first and most important consumer of this software? Who's it really for, anyway?
That should do it. For today, please create at least a complete paragraph for each point as a rough draft. When you are finished, please email it to me with your name and "my killer app" in the subject line
Cheers,
Uncle Paulie
Thursday, May 28, 2009
Thursday May 28: UberGeek SoundOff
In a recent class, there was a happy accident whereby two completely different ideas met in the luxuriant garden that is my mind, fell in love and gave birth to a third idea that combines the two. The first was that I had asked each of you to post to our discussion group some sense of what it means to you personally to be involved with computer programming, ie, "what's it all good for?" The second was that a few of you had casually mentioned that even though we've meeting right next door to it, and even though you've been attending this school for this entire year, and perhaps more years than one, you had never even seen the inside of the radio production rooms next door to this class.
What has sprung in my ever-moving and often randomly creative mind is that today, for those of you who are interested, I would like to give each of you a brief tour of the facility, and perhaps give you a brief run through with the equipment. This can only take place if ALL of us agree to the following conditions:
A) I cannot take in the entire class at one time. At best, I can get four of you in at a shot
B) Those of you who are awaiting your turn or have finished it need to work quietly and appropriately in our class on your projects
C) If you wish to make a brief recording, it should be on a topic related to this class and MUST be school appropriate at all times
D) Naturally, you must be respectful and careful of the equipment. All computers are worthy of respect, whether they have microphones attached to them or not.
If we can all agree to that, I think that this would be a good experience for all. I have had many other students from outside the radio class take part in similar projects, and it has been extremely helpful in promoting the unique resources we have here at HHS. Since most of you are in the 9th or 10th grade, it may even be that you will be interested enough to take one of the Radio classes offered here, since you will be here for at least another 2 or 3 years
Please undertsnad that there is nothing in the least bit mandatory about any of this, and if this is an activity in which you have no interest, you are not required to take part. You will have to stay in the regular classroom however, as I think running down the hall screaming like a nut would probably attract undue attention.
So, let's look at some new technology, m'OK?
Cheers,
Uncle Paulie
Wednesday, May 20, 2009
Thursday May 21: so what's it all good for?
Towns, cities and states all across America are screaming for money to run various different programs, and some of these have to do with education. Technology instruction is part of education, so what we do here in this class -- and in future classes-- is affected by all this. So what I'm asking you to think about and then write into a group discussion post is this: what's it all good for? How do we justify spending money on technology instruction? How do we keep classes that we already have and try to offer more?
What I would like each of you to do is to write a group discussion post of at least two paragraphs of at three complete sentences each detailing why you believe that what we do here is important, and what we can say convince others of the basic value of what we're all about. As part of that, let's try to discuss ways in which the technologies we pursue can actually save money, for everyone, not just us. Additionally, let's try to discuss what each of us believes to be the items that should be part of any program of technology instruction.
After that, you can continue with your game projects,
cheers,
Mr. L
Tuesday, May 19, 2009
Tuesday May 19th: for the record!
Today, I have a somewhat different request...I'll tell you what it is, then I'll explain why I need this done:
A) I will need you to email me as an attachment the latest copy of your current project. Along with this attachment, as a paragraph in the main body of the email, I will need a description of how to do ONE thing in this program, in a "step by step" fashion
B) the reason I need this is because I want to "film" your program in action, doing the thing you said that it can do. I have a program to record this, and I wish to make a brief video of each of your programs
OK, let's get on with that, so i can get filming and yopu can keep coding
Cheers,
Mr. L
Friday, April 24, 2009
Monday May 18: JN25, part five
Here's what to do:
A) first off, we add a KeyListener along with all those other listeners at the top of the program, like so (MAKE IT LOOK LIKE THIS, DO NOT ADD ANOTHER WHOLE LINE):
implements ActionListener, ChangeListener, ItemListener, KeyListener
B) If this key listener thing sounds familar, well it should: your classmate Evan taught this to you weeks ago
C) The KeyListener requires that three methods be declared, even if you only are goiong to use one of them. Hey, I didn't set it up that way...not my idea! Anyway, just add this block underneath the (STILL empty) actionperformed code block
public void keyTyped(KeyEvent e) { }//empty method
public void keyPressed(KeyEvent e)
{
}// we will use this method
public void keyReleased(KeyEvent e) { }//empty method
D) Now the next step will use a switch case, which is similar to an if statement, but is especially adept at using ints. Here's the first small part which we will setup INSIDE the curly braces for the keyPressed(KeyEvent e) method
switch (e.getKeyCode()) //every key has an integer keyCode
{
case KeyEvent.VK_Q: // 1st in array?
whichOne=0;
break;
case KeyEvent.VK_W: // 2nd in array?
whichOne=1;
break;
case KeyEvent.VK_E: // 3rd in array?
whichOne=2;
break;
case KeyEvent.VK_R: // 4th in array?
whichOne=3;
} //end switch case
System.out.println(whichOne); //show value of integer in console
String codedStuff = enc.getText(); //get the stuff already in code JTextArea enc.setText(codedStuff + coded[whichOne]);//add new stuff into code JTextArea
} //end keypressed
E) The quick ones among you will have already figured out that this method receives input in the form of a key that's been pressed, then uses that key to set the value of an integer. This intger then points to an element in the coded Array, and then types that String to the other JTextArea, appending it at the end of encrypted text thats already there.
The entirety of the switch case can be found here:
http://www.box.net/shared/ppxd8c35tz
cheers,
Mr. L
Monday May 18: JN25, part four
1) It will set up for the beginning of next wek, when we can have some $#+33^ 6((3 fun with this program
2) it will demonstrate how you can use arrays and loops to create large numbers of similiar components
3) It will show some fun stuff you can do with swing type labels
OK, here we go again
A) In the "declarations" section of this program, you will add two new JPanels, two JLabels and twoArrays, like so:
JPanel alpha,omega;
JLabel noCode, crypto;
//use with clear JTextArea & noCode JLabels
String[] qwerty ={"q","w","e","r","t", "y", "u", "i","o","p","a","s","d","f","g","h","j","k","l"," ","z","x","c","v","b","n","m", ".", ",","!"};
//use with enc JTextArea & crypto JLabels
String[] coded ={"!","@","#","$","%", "^", "&", "*","(",")","+","=","{","}","[","]","1","2","3"," ","4","5","6","7","8","9","0", ".", ",","!"};
You will notice that each array has thirty elements and that both are String arrays. If you believe that they can be used together for a simple cypher, you guessed correctly
Compile and run now to make sure you have no errors before we proceed
B) Just above the end of the constructor line that makes the program visible, add this method call:
addAlpha(); //call method set up clear keys
C) create this new method just below the (STILL!) empty actionPerformed method block:
//method to populate JLabels for clear keys
public void addAlpha()
{
alpha = new JPanel();
alpha.setBounds(20,150,300,200);
alpha.setLayout(new GridLayout(3,10));
for (int i = 0; i <
{
noCode = new JLabel(qwerty[i],SwingConstants.CENTER); //create a label noCode.setBorder(new LineBorder(Color.blue, 3)); //give it a blue border
alpha.add(noCode); //add label to Panel
System.out.println(qwerty[i]);
}
//end for loop fill clear labels
Ultra.add(alpha); //add panel to container
}//end addAlpha
OK, that's great, but what does it all mean? Well, let's break it down:
1) You're making a new JPanel, with a GridLayout of three rows of ten
2) You're using a for loop that will run the "length" of the qwerty Array
3) each pass through the for loop creates a new JLabel that has the text found at the position in the qwerty Array that is the same as the value of "i".
4) So if is 4, then you go to position 4 in the array, which is the letter "t", and thats what gets put in that label
5) each JLabel gets a pretty blue border whose thickness is set to 3
6) the value of the label text gets outputted to the system console
7) when the loop is done and the JPanel is filled, put the JPanel into the container
30 labels in an eyeblink!
Cheers,
Mr. L
Wednesday April 29th: JN25, part three
A) Add a new "listener" at the end of the line that says "implements ActionListener, ChangeListener"
so that it reads implements ActionListener, ChangeListener, ItemListener
we need an itemlistener here because comboboxes are basically lists of items, in this case, font names
B) In the constructor, add the code for creating the JComboBox and its JLabel JUST BELOW WHERE YOU ADDED THE SLIDER AND ITS LABEL
Here is the code you add:
//add array elements to JComboBox
daFonts = new JComboBox(typeStyle);
daFonts.setSize(150,25);
//add itemlistener to combobox
daFonts.addItemListener(this);
setWordz.add(daFonts); //add combobox to panel
whatDaFont = new JLabel("Please Choose a Font",SwingConstants.CENTER);
whatDaFont.setSize(150,25);
setWordz.add(whatDaFont); //add JLabel for combobox to panel
C) As you might imagine, you have to add a new ItemListener method to handle the event of you choosing a new font from the list. Here it is, and please enter it just below the other one you made yesterday:
public void itemStateChanged(ItemEvent e)
{
//set String variable for font style to item chosen in combobox
whichFont = daFonts.getSelectedItem().toString();
ChangeDemWordz(); //call method set size and font of JTextAreas
}//end itemStateChanged
As you can see, you're setting a String variable equal to whatever has been chosen from the JComboBox, then calling the same method from yesterday to apply it to text that gets typed
See how easy?
Mr. L
Tuesday April 28th: JN25, part two
setWordz = new JPanel();
//new JPanelsetWordz.setBounds(250,380,300,50);
setWordz.setLayout(new GridLayout(2,2));
daSizes = new JSlider(); //new JSlider
daSizes.setValue(fontBigness); //start at default font size
daSizes.setSize(150,25);
wowSoBig = new JLabel("Slider Sets Font Size",SwingConstants.CENTER);
{
Tuesday May 12th: JN25, part one
There is a file called "JN25" which you will need to download from a folder found here:
http://www.box.net/shared/aha47pf4fi
When you compile and run it, you will find a very simple program which actually doesn't have much in it just yet. There are only two simple things we are going to do with this program:
A) add two JTextAreas inside two JScrollPanes which have vertical scrollbars, just like those we put the JEditorPanes inside a few weeks back
B) add a small correction to a slight problem you will no doubt notice almost immediately
For part A, we need to construct two JTextAreas that are next to each other. Here's how the first one gets built:
in the programs constructor, just below where it states that the JFrame's container has a "null" layout, enter in this code block:
clear = new JTextArea("", 20,20);
clear.setBounds(10,10,400,100);
clearScroll = new JScrollPane(clear);
clearScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
clearScroll.setBounds(10,10,400,100);
Ultra.add(clearScroll);
This adds a new JTextArea, which unlike a TextField, has multiple rows as well as many columns: how many has been determined by the 20,20 ints above
The JTextArea is added inside a scrollpane, because if you end with lots of text in it, you might need to scroll up and down to read it all
The ScrollPane is then added to the container, and since that container's layout is set to null, you need to setBounds on the ScrollPane to determine where it gets placed.
Once you have that set up, all you need to do to put the other JTextArea/scrollpane onto the program is to copy and paste the code block from above, paste it right below that first code block in your program, then change the neame of the JTextArea from "clear" to "enc" and the name of the JScrollPane from "clearScroll" to "encScroll".
And of course, you have to change WHERE the second textarea/scroller is placed. Hint: if you set the first int valuein "setBounds" to something bigger than "10", say "450", that should do it
OK, one last thing: when you type in either of these JTextAreas, you will notice that they don't "word wrap" Even though the JScollPane has a vertical scrollbar. !!!!#!@##!~!!!!!!!
fear not though: you can control that by adding these three lines just below where you setbounds for the first JTextArea:
clear.setEditable(true);
clear.setLineWrap(true);
clear.setWrapStyleWord(true);
Make sure to do it for the other JTextArea as well. When you're done, your groups may proceed onwards with your game projects
Cheers,
Mr. L
Monday April 27th: Before we begin, a simple poll
Before we begin, I would like for you to meet as teams and decide how much additional time you will require to work on your game projects. We can either limit it to the rest of this week, or extend it to include both this week and next week. So, it either ends May 1 or May 8.
Decide by teams and then make one group discussion post per team. The subject line should include all the names of the people working together as a group, followed by either the May 1 or the May 8 deadline.
Additionally, each team should indicate if they feel the need to have the entirety of today's class devotd to their project or not. I have several techniques that I would love to demonstrate, but they can wait if you need the additonal time
Lastly, in the body of your post, please indicate whether or not your team feels sufficiently confident of your program to be able to present it to the rest of the class, field questions, ect etc.
Once that is done, we can go on to the next step
Cheers,
Mr. L
an "E"
Wednesday, April 15, 2009
wednesday April 15th: prepping for beyond the break
as you may have guessed, I am not in today. That being the case, I have decided to go forward with two items I meant to work on after the break, to wit:
A) Anything that you have
B) Begin setting up a list of basic (no, I can't hear you from here) ideas for developing some sort of game program in Java, using knowledge which already have and employing both AWT and Swing components as needed. I'm not necessarily talking about WoW or Halo -- obviously-- but something a little more doable. When I return, I'll demonstrate something along those lines. Here are some things you should consider for your game:
1) What is the object of the game?
2) does it have identifiable characters?
3) does it have multiple skill levels?
4) how does it register input?
5) can it have more than one player?
6) how does it keep score?
7) how do you determine when the game ends?
8) can you save games? high scores? levels
9) can you "build" a character? -- (that'd be a bit more difficult, but perhaps fun to try)
Please think about these issues, then create a Group discussion post named after yourself, plus the phrase "Java gaming". Describe what you have in mind for your game.
And yes, in answer to your question, you may work with partners on this if you wish. Please include that in your posts...but remember, ALL of you must make that first post.
Mr. L
Saturday, April 11, 2009
Monday April 13th: Improving our "browser"
If you will recall, last week, before Evan made some noise with you and I showed you a little bit about JToolbars, we wer working on a kind of "browser": not exactly Firefox, but it was a start. I had told you that at some point, I would show you how to modify this program so that Favorites you added would STAY in your favorites list, by using some basic File reading and writing capabilities.
Before I go any further, I want to point out from the beginning that there are some obvious "bugs" in the way this program is setup. My purpose in doing this is to get you to think about how YOU would fix the errors, as well as being able to look for them in the first place. If you don't know there's a problem, it's kind of like that giant squid in the Family Guy episode: it's there, whether you acknowledge it or not.
Also, there's a file that I used in this version of the program which you can download here:
http://www.box.net/shared/n32n5qk2qs
It's called "addys.pml". Later on, you can modify this file, but for now, you can just use it as we progress through this lesson.
so OK, here we go:
The improvement to be made today involves being able to REALLY save favorites to a list. In the most recent incarnation of this program, you were able to use an "Add to Faves" button to add a particular website address to your JComboBox; but when the program closed, all those newly added Favorites were lost.
The solution is to use some elemental File writing and reading capabilities to your program. If your favorites list is built by reading from a separate text file, then it follows that anything you WRITE to that file during the course of running the program should be available the next time you run it. Here's what I did:
In your constructor, you should have a code block that looks like this:
webURL = new Vector();
webURL.addElement("http://www.google.com");
webURL.addElement("http://www.thinkgeek.com");
webURL.addElement("http://www.yahoo.com");
webURL.addElement("http://www.foxnews.com");
You need to comment out that entire block!
Well now, if you do that, your Favorites list will be empty. So, we've gotta find some other way of populating it. Here's what I did:
Just below the stuff I commented, I made a method call:
readFilesMakeFaves(); //call this method
This means I have to create the method that will be called; just make sure you don't embed this thing inside another method. That would be bad. Here is what my method looks like:
private void readFilesMakeFaves( )
{
webURL = new Vector();//create vector
//add to that vector using file read
try {
BufferedReader in = new BufferedReader(new FileReader("addys.pml"));
String str;
while ((str = in.readLine()) != null)
{
System.out.println(str); //show whats going into file in system console
webURL.addElement(str); //add to the vector the line just read
}
in.close( ); //stop reading
}
catch (IOException e)
{System.out.println("file not found or is null"); }
}//end readfilemakefaves method
So what this filereader does is to open up the file called "addys.pml", and read it one line at a time. As it does so, it adds each line to the JComboBox. It also prints out each line to the System console. So far, so good!
The next step is to modify the "Add Faves" button so that it can add a favorite as a line into the "addys.pml" file. This will mean that even if you close the program and then re-start it, the new favorites places that has been added will STILL be in the list, which is an improvement over the previous system. Here is how I did it:
private void addFaves()
{
//read into the addy.pml file the address in JTextField
try {
//open a writer to append to end of addys.pml file which stores faves
BufferedWriter out = new BufferedWriter(new FileWriter("addys.pml", true));
out.newLine(); //drop to next line
out.write(WhereTo.getText()); //write in contents of JTextField
out.close(); //stop writing fer cryin' out loud
}
catch (IOException e) { }
OK, here's what I want you to do after you've saved, compiled and run this thing:
A) At some point, I will want you to add a JToolbar to this program which will have graphical buttons that provide another way of doing the stuff we've already been doing with this programB) There's at least one glaring omission with this program, something it should do but doesn't. Figure out what it is, then figure out YOUR way to fix it.
C) After you've done both A and B above, please make a discussion post describing the problem you found and your solution.
D) Please email your completed program before the end of the class.
Cheers,
Uncle Paulie
Thursday, April 9, 2009
Thursday, April 9: Evan's at bat and here's the rest of the code!
//this boolean called keydown sets the key so if it is pushed, the sound will play.
{
if(key=='q'key=='Q')
{
if (lowCPlaying == false)
{
lowC.loop();
}
lowCPlaying = true;
}
if(key=='w'key=='W')
{
if (lowDPlaying == false)
{
lowD.loop();
}
lowDPlaying = true;
}
if(key=='e'key=='E')
{
if (lowEPlaying == false)
{
lowE.loop();
}
lowEPlaying = true;
}
if(key=='r'key=='R')
{
if (lowFPlaying == false)
{
lowF.loop();
}
lowFPlaying = true;
}
if(key=='t'key=='T')
{
if (lowGPlaying == false)
{
lowG.loop();
}
lowGPlaying = true;
}
if(key=='y'key=='Y')
{
if (lowAPlaying == false)
{
lowA.loop();
}
lowAPlaying = true;
}
if(key=='u'key=='U')
{
if (lowBPlaying == false)
{
lowB.loop();
}
lowBPlaying = true;
}
if(key=='i'key=='I')
{
if (midCPlaying == false)
{
midC.loop();
}
midCPlaying = true;
}
if(key=='o'key=='O')
{
if (midDPlaying == false)
{
midD.loop();
}
midDPlaying = true;
}
if(key=='p'key=='P')
{
if (midEPlaying == false)
{
midE.loop();
}
midEPlaying = true;
}
if(key=='a'key=='A')
{
if (midFPlaying == false)
{
midF.loop();
}
midFPlaying = true;
}
if(key=='s'key=='S')
{
if (midGPlaying == false)
{
midG.loop();
}
midGPlaying = true;
}
if(key=='d'key=='D')
{
if (midAPlaying == false)
{
midA.loop();
}
midAPlaying = true;
}
if(key=='f'key=='F')
{
if (midBPlaying == false)
{
midB.loop();
}
midCPlaying = true;
}
if(key=='g'key=='G')
{
if (highCPlaying == false)
{
highC.loop();
}
highCPlaying = true;
}
return true;
}//end keyDown method
public boolean keyUp (Event e, int key)
//this makes a boolean so when the key is not being pushed the sound will stop.
{
if(key=='q'key=='Q')
{
lowC.stop();
lowCPlaying = false;
}if(key=='w'key=='W')
{
lowD.stop();
lowDPlaying = false;
}
if(key=='e'key=='E')
{
lowE.stop();
lowEPlaying = false;
}if(key=='r'key=='R')
{
lowF.stop();
lowFPlaying = false;
}if(key=='t'key=='T')
{
lowG.stop();
lowGPlaying = false;
}if(key=='y'key=='Y')
{
lowA.stop();
lowAPlaying = false;
}if(key=='u'key=='U')
{
lowB.stop();
lowBPlaying = false;
}
if(key=='i'key=='I')
{
midC.stop();
midCPlaying = false;
}
if(key=='o'key=='O')
{
midD.stop();
midDPlaying = false;
}
if(key=='p'key=='P')
{
midE.stop();
midEPlaying = false;
}
if(key=='a'key=='A')
{
midF.stop();
midFPlaying = false;
}if(key=='s'key=='S')
{
midG.stop();
midGPlaying = false;
}
if(key=='d'key=='D')
{
midA.stop();
midAPlaying = false;
}
if(key=='f'key=='F')
{
midB.stop();
midBPlaying = false;
}
if(key=='g'key=='G')
{
highC.stop();
highCPlaying = false;
}
return true;
} // end keyUp method
Wednesday, April 8, 2009
Thursday, April 9: Evan's at bat -- and man is he LOUD!
hello grand privateers - this is your BloodSail Admiral, Abquhazar!
Today we will be looking at a simple sound player. I attempted to make this in Visual Basic but I Epic failed.... and yet somehow, I got it in JAVA!
but any ways, we are going to learn how to play the violin today =D
lets break this down shall we?
we are gonna start this with the usual... please download the initial file at
http://www.box.net/shared/nf2gty9c0i
It has the startup file with three empty methods: init, keyDown and keyUp
The file is meant to be played as an Applet, btw.
now lets declare some things; we will do that just ABOVE the init( ) method:
AudioClip lowC, lowD, lowE, lowF, lowG, lowA, lowB, midC, midD, midE, midF, midG, midA, midB, highC; //all this stuff should go on one line!
int keyPressed;
I made enough sound files to play 2 octaves in C Major. Personally, C Major is my favorite scale but if you're not into music theory its all the same.
now we declare some booleans....you know, things that are either true or false. In this case, we wanna know if a particular note is playing....
boolean lowCPlaying,lowDPlaying,lowEPlaying,lowFPlaying, lowGPlaying, lowAPlaying, lowBPlaying, midCPlaying,midDPlaying, midEPlaying, midFPlaying,midGPlaying, midAPlaying, midBPlaying, highCPlaying;
//all this should should go on one line!!!
Once again, Iused 2 octaves of notes in a moajor scale.... thats 16 notes right there.
ok, so now get into our public void - once again, we have many sound files to load so lets get crackin'.
Fill this empty init method so that it looks like this:
public void init( )
{
try
{
lowC=getAudioClip(getCodeBase(),"lowc.mid");
lowD=getAudioClip(getCodeBase(),"lowd.mid");
lowE=getAudioClip(getCodeBase(),"lowE.mid");
lowF=getAudioClip(getCodeBase(),"lowF.mid");
lowG=getAudioClip(getCodeBase(),"lowG.mid");
lowA=getAudioClip(getCodeBase(),"lowA.mid");
lowB=getAudioClip(getCodeBase(),"lowB.mid");
midC=getAudioClip(getCodeBase(),"midC.mid");
midD=getAudioClip(getCodeBase(),"midD.mid");
midE=getAudioClip(getCodeBase(),"midE.mid");
midF=getAudioClip(getCodeBase(),"midF.mid");
midG=getAudioClip(getCodeBase(),"midG.mid");
midA=getAudioClip(getCodeBase(),"midA.mid");
midB=getAudioClip(getCodeBase(),"midB.mid");
highC=getAudioClip(getCodeBase(),"highC.mid");
}//end try
catch (Exception e){ } //end empty catch
} //end init
You have to use a "try catch" to init the sounds for the same reason you use it when loading a webpage: you have to have a "just in case' event in case the sounds aren't there.
So now after all the sounds are loaded, we will set up keydown commands to play the sound! We will put this in the boolean called "keyDown". Here we go...
INSIDE the public boolean keyDown method, just above the "return true" statement, add this:
if(key=='q'key=='Q')
{
if (lowCPlaying == false)
{
lowC.loop();
}
lowCPlaying = true;
This is just one sound. lets see if you can figue some of this out - I'll put the next post up in a few minutes to show the rest...
now as we might realize, there is no way to stop the sound once is has played... SO we are gonna have to make another boolean called keyUp. now im not going to tell you how to fix this problem just yet... lets have your brain go for a little jog...
any one get it? Well here is the spoiler for all the n0obs who didnt try....
Put this in the keyUp method, just above the "return true"
if(key=='q'key=='Q')
{
lowC.stop();
lowCPlaying = false;
}
Save, compile, then run the program...when you do, you should be able to play a low C when you press the "Q" key.
The rest of the program is about adding in more if statements to both the keyUp and keyDown methods: other sounds connected with other keys. See if you can figure that out on your own....if not, then I'll give ya the complete set in another blog post
Tuesday, April 7, 2009
Wednesday, April 8: Tooltips and rollovers and Togglers, O my!
Smile.setToolTipText("Always look on the bright side of life!");
then re-compile and run the program. You should get a message that pops up each time you leave the mouse over any particular JButton.
Speaking of rollovers, if you add this line of code:
Utool.setRollover(true);
after this liner of code
Utool.setFloatable(true);
you will get another effect showing which JButton you are about to select
OK, now for our other component, the JToggleButton. This component acts like a kind of light switch: it has an on and off position, and you can make things happen in your program based on that. It can be added to your JToolbar like any other JButton, and it can make use of another type of Listener, an "ItemListener" (This type of listener can also be used by radio buttons, but we'll get to that some other time) So, first things first, lets add an ItemListener to your program:
add this , ItemListener
after this implements ActionListener
put 'em both on the same line
then, declare this:
JToggleButton JTB;
and then add it into memory like so
JTB = new JToggleButton(new ImageIcon("gearHead.jpg") );
JTB.setToolTipText("Gear Up, Mates!");
JTB.addItemListener(this);
Utool.add(JTB);
Finally, you need to add an ItemStateChanged method to your program. You can probably do this just below your actionPerformed method, that's where I did it:
public void itemStateChanged(ItemEvent evt)
{
if (evt.getStateChange() == ItemEvent.SELECTED)
{
Utool.setFloatable(false);
}
else
{
Utool.setFloatable(true);
}
}//end itemStateChanged
Cheers,
Uncle Paulie
Wednesday, April 8: and now for something completely different...
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
Sunday, April 5, 2009
Monday April 6 : additional stuff for our Swing Browser
Today is going to be a simple two step process:
A) I will show you something pretty simple to do, that can be applied to ANY program you create here, that's pretty cool, AND its a response to a request that several of you had made.
Sometimes, you just gotta give the people what they want...
B) After that, you will have the rest of the class to further develop this mini browser we've been working on. Add to it something that we've worked with before, perhaps a menu or the ability to make use of saved files to extend its capabilities.
Remember, BEFORE the class ends, email me your completed program with its new powers, AND make a post on our Google group titled "what MY browser can do"
OK, so here's something easy and cool to do that will work with any program:
0) open the folder where your mini browser is stored
1) start up TextPad, and open your mini browser program
2) start up a new document, and type the following:
start javaw CreateTabbedPane
where "CreateTabbedPane" is the name of the class file you wish to run.
DO NOT add the ".class" extension
3) save this new file as StartBrowser.bat INSIDE THE SAME FOLDER AS YOUR PROGRAM. make SURE you add that ".bat" extension
4) This will make a batch file inside your folder that you can click on. Doing so will start your minibrowser program WITHOUT the annoying, telltale "command prompt" window --> that's why you use "javaw" to invoke your program
5) But wait there's more! It's not sold in any store! If you create a shortcut to this batch file, you should be able to drag that shortcut anywhere, even onto your Start button, which will make it part of the Start menu
6) But wait, there's STILL more ! If you right click on your new shortcut, and then click on "Properties", you can go to the "shortcut" tab, then click on the "Change Icon" button. This allows you to browse for an icon that looks cooler than the little gear thingy looking device you're using now
7) But wait: if you call RIGHT NOW, you can go to this address:
http://www.iconarchive.com/
and download any kind of icon file you want. Just download them to your folder, and then when you change the icon, just browse top your folder, and choose the icon you like :-)
Cheers,
Uncle Paulie
Thursday, April 2, 2009
Friday April 3: Java Swing Tabbed Browsing part Six
A) I declared a new button:
JButton Bravo;
B) created it in memory and added to the program, giving it an actionlistener:
Bravo = new JButton("Add 2 Faves");
Bravo.setBounds(460,0,130,20);
Bravo.addActionListener(this);
ButtonsAndText.add(Bravo);
C) Add another "else if" to our actionPerformed:
else if (e.getSource() == Bravo)
{
addFaves(); // make method call
}
D) create the new method that is being called
System.out.println("everybody, do the monkey!");
webURL.addElement(WhereTo.getText()); //add to vector
myWebPlaces = new JComboBox(webURL); //reload vector to combobox
That should about do it, And once you've mastered that, you know what I'm looking for:
1) add something you already know about to this program
2) make a posting about what you did today while working with this program
Have a helluva weekend,
Uncle Paulie
Wednesday, April 1, 2009
Friday April 3: Java Swing Tabbed Browsing part Five
A) It would require having to make a MenuBar, Menu and several menuitems... too much work
B) We can accomplish the same goal using what's known in Java as a "ComboBox", aka a "pulldown menu". Plus, if we connect this ComboBox to a Vector (remember that component? Told you we'd use 'em again), it might be possible to make the list expand to hold more websites
C) I'm too old, too stubborn and too big to be prevented from using a ComboBox.
So anyway, here's how I did it, perhaps some of you have another idea. I would love to see them :-)
Add this import for using Vectors
import java.util.*; //for use with vectors
add these to your declarations section:
Vector webURL; //to hold addresses
JComboBox myWebPlaces; //to display those addresses
Add these two components to your constructor:
webURL = new Vector( );
webURL.addElement("http://www.google.com");
webURL.addElement("http://www.thinkgeek.com");
webURL.addElement("http://www.yahoo.com");
webURL.addElement("http://www.foxnews.com");
myWebPlaces = new JComboBox(webURL);
myWebPlaces.setEditable(true);
myWebPlaces.setBounds(300,0,100,20);
myWebPlaces.addActionListener(this);
ButtonsAndText.add(myWebPlaces);
Add this “else if” to your actionPerformed
else if (e.getSource( ) == myWebPlaces)
{
System.out.println(myWebPlaces.getSelectedItem());
StartPage= myWebPlaces.getSelectedItem()+ "";
makeTab( ); //call method, make new tab with selected page
}//end using combobox
Now obviously, if you want to use a different set of websites, or a different number of them, go right on ahead. Let's see what's in your fridge!
code is good food,
Uncle Paulie
Friday April 3: Java Swing Tabbed Browsing, part Four
Well, its true, a JeditorPane by itself will not scroll down to see all the stuff on a webpage that's too big to fit...that's why you need a "JScrollPane". What we will do is to put the JEditorPane which holds your webpage inside a JScrollPane which is added to the JTabbedPane which is added to a Container which is added to a JFrame.
Holy crap..supply lines are getting longer and harder to maintain!
Add this to your declarations
JScrollPane scrollTheWeb; //to make webpages scroll
Add this to the “try catch” in the method makeTab( ),
//put webpage container inside scroller
scrollTheWeb = new JScrollPane(newWeb);
scrollTheWeb.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
Just below where you have this line:
newWeb.setBounds(10,50,850,720);
and then change this line
Tabitha.add("Page " + pageNumber , newWeb);
To look like this
Tabitha.add("Page " + pageNumber , scrollTheWeb);
Shazzam!
Uncle Paulie
Tues April 1: Java Swing Tabbed Browsing, part Three
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
Tues April 1: Java Swing Tabbed Browsing, part Two
Very tru, O impatient ones, but there is a simple solution: create a button that calls the method that made the first tab. Try to see if you can figure that out on your own (I'm betting some of you already have). Try it yourself, and if you can't do it for real the solution is way down at the end of this posting
Cheers,
Uncle Paulie
See, I told you I would give you a solution...now could you try doing this yourself next time?
Add this to your constructor:
Pinky = new JButton("New Tab");
Pinky.setBounds(0,0,130,20);
Pinky.addActionListener(this);
ButtonsAndText.add(Pinky);
Add this to your actionPerformed method
if (e.getSource( ) == Pinky)
{
makeTab( ); // make method call
}
Tues April 1: Java Swing Tabbed Browsing, part One
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
Tuesday, March 31, 2009
Tuesday March 31: taste the HTML rainbow, part four
"HyperlinkListener"
Here's what you do:
add this -- > , HyperlinkListener
after this: implements ActionListener
add this:
Webapalooza.addHyperlinkListener(this);
underneath
Webapalooza.setEditable(false);
add this code block underneath the actionPerformed method:
public void hyperlinkUpdate(HyperlinkEvent evt)
{
if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
{
try
{
Webapalooza.setPage(evt.getURL());
} //end try
catch(IOException ioe)
{ } //end catch
}//end if
} //end hyperlinkEvent
Tuesday March 31: taste the HTML rainbow, part three
Declare these two components
JTextField WebAddy;
JButton ChangeAddy;
then add these two components to your constructor:
//create JTextField, set text to first webpage String
WebAddy = new JTextField(StartPage);
WebAddy.setBounds(345,0,200,20); //size and place it
WebAddy.addActionListener(this);
ProvingGround.add(WebAddy); //add to container
ChangeAddy = new JButton("Go There"); //create JButton
ChangeAddy.setBounds(180,0,165,35); //size and place it
ChangeAddy.addActionListener(this);
ProvingGround.add(ChangeAddy); //add to container
add an "else if" statement for the ChangeAddy JButton
else if (e.getSource() == ChangeAddy)
{
//StartPage = WebAddy.getText( );
try {
Webapalooza.setPage(new URL(WebAddy.getText()));
// urlField.setText(url);
} //end try
catch(IOException ioe)
{
System.out.println("crap!");
}//end catch
}//end else for ChangeAddy JButton
Save, compile and run; you should be able to load another website into your JEditorPane by typing the address in the JTextField then hitting the new JButton
Cheers,
Uncle Paulie
Tuesday March 31: taste the HTML rainbow, part two
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: taste the HTML rainbow, part one
Today, we shall continue onwards with an exploration of Java Swing; and the first step on this journey is to download the file located here:
http://www.box.net/shared/j6j4def1kc
The file inside is functional and will start up a JFrame with a pretty red background. It has an empty actionPerformed method, and its setup so that when you close the JFrame, you shut down the whole program. Beyond that, it doesn't do much; there's not even a component that could make anything happen. So let's change that right now, m'OK?
A) just below this line in the declarations section:
Container ProvingGround;
add this line to declare a JButton:
JButton Skittles;
B) In the constructor, just below this line:
ProvingGround.setLayout(null);
add this code block to create and enable the JButton you just declared:
Skittles = new JButton("Taste The Rainbow");
Skittles.setBounds(0,0,165,35); // null layout makes you use this
Skittles.setBackground(Color.blue);
Skittles.addActionListener(this);
ProvingGround.add(Skittles);
C) Finally, and most importantly, you have to add an if statement to your actionPerformed method, so that when you click the "Skittles" button, it pops up what's known as a JColorChooser Dialog. This dialog box allows you to choose a color, either by clicking on a box, or by setting integer values; you can then apply this color to the Container background:
if (e.getSource() == Skittles)
{
//pop up JColorChooser dialog box
Color TieDye = JColorChooser.showDialog(this,"Hey Man, the Colorz!", getBackground());
if (TieDye != null) //chose a color?
//change the Container Color to what you chose
ProvingGround.setBackground(TieDye);
}// end choose color Skittles button
PLEASE NOTE: the line that starts with "Color TieDye" got wrapped to the next line; please put both lines you see here on one line.
OK, that oughta do it; compile it and run, then see if it works for you.
Btw, if you somehow can apply the colors you find in this dialog at runtime, that would be cool. Not necessary, but cool.
Cheers,
Uncle Paulie
Sunday, March 29, 2009
Monday March 30: add a JMenu !
And a special challenge: see if you can get an image onto one of your JMenuItems. The code is pretty darned similar to the stuff we've just done
Cheers,
Uncle Paulie
Monday March 30: a null layout for the whole program? Sort of....
//make a Toolkit object
Toolkit TK = getToolkit();
//use toolkit object to find screen size
Dimension size = TK.getScreenSize();
//subtract 1/2 the width of JFrame from 1/2 the width of screen
//do the same for height
setLocation(size.width/2 - getWidth()/2, size.height/2 - getHeight()/2);
The Toolkit is actually part of the AWT libraries, but as you can see from this example, it can be used even with swing based programs. It has its best use when creating a Splash screen: a window controlled by a Timer bearing some sort of information about the program. It lasts for about 5 to 10 seconds, then vanishes to be replaced by a Frame , or JFrame in this case
OK, onwards to see if yuo can handle a VERY small leap!
Uncle Paulie
Monday March 30: SWING into spring with a new layout and a new startup position
Well, its almost one of my favorite days, April 1, and to celebrate, I want to start this week off by looking at an updated version of Java called "swing". There's three things you should know right off the bat:
A) Everything in Swing is typed the same as in AWT, but with a "J" in front of it: JFrame, JButton, JTextField, etc etc
B) Swing components like JButtons are not loaded directly onto JFrames, but into "Containers"
C) There's some cool new things you can do in Swing that you can't do in AWT
OK, so let's get going. There's a folder online at Box.net that has two files in it: one a Java file which you will build on, the other being a small image file. Please download both from here:
http://www.box.net/shared/010jen6jjn
and put them into a folder named after yourself plus the word "swing"
When you load this program into TextPad, you will notice that there is a line of code that ends with "(EXIT_ON_CLOSE)" What this does is to close the JFrame AND shut down the program.
You will also notice that the JFrame has a Container object which will be used to hold components AND its layout has been set to "null". This allows you to position components exactly where you want them; BUT, you have to use the "setBounds" method for pretty much all of them. So OK, let's add a swing component and see it happen:
right below this line of code:
ProvingGround.setLayout(null);
add these lines:
JButton NewButton = new JButton("Look A JButton!");
NewButton.setBounds(0,0,165,65);
ProvingGround.add(NewButton);
compile it and run it, and you will see a button. No big deal; except, let's add another one and see if we can get something a little different:
ImageIcon buzzed = new ImageIcon("Feine.gif");
JButton PicButton = new JButton(buzzed);
PicButton.setBounds(100,200,195,65);
ProvingGround.add(PicButton);
ImageIcons can be used to add images to components, including, well JButtons. Notice that this image was found in the same folder as your program; if it was elsewhere, you'd need to somehow inform your program of this.
Let's try one more:
JButton ImageNtexT = new JButton("Wired", buzzed);
ImageNtexT.setBounds(300,100,165,65);
ProvingGround.add(ImageNtexT);
OK, for our next trick, let's look at doing some absolute positioning for the JFrame itself. Onward to the next posting!
Ubcle Paulie
Thursday, March 26, 2009
Thursday March 26: Projects must be finished up and handed in today!
Today, we have a lunch block. It's also the last time I will meet with you this week, and its effectively the last time we will meet for this marking period. With that in mind, it's time for you to finish the projects we started back in the middle of the month. The requirements for your projects were listed HERE
Please finish up to the best of your ability. You have a great deal of time, and you may use all the resources available, including all previous posts, all group discussions, all previous programs, each other, and me. You may also of course apply techniques you have learned outside the coursework I have assigned, including that taught to you yesterday by one of your peers.
Make sure to send me by attachment ALL files relevant to your project, and remember to put your name and the phrase "last version" in the subject line.
Also, you will need to create a final post to do with this project; in it, I will need you to record all thoughts, observations and suggestions for future projects.
Cheers,
Uncle Paulie
