Do It Yourself Graphical User Interfaces
Chapter 12 of Head First Java goes over the ins and outs of creating GUIs - Graphical User Interfaces. We learn to deal with Event Handling and Inner Classes while moving from command line inputs and outputs to creating our first graphical anything.
This chapter has taken me four days to get through; in part because it's a long chapter, partly because I've been busy with the house and family, but mostly because it's been difficult for me to understand. Not to mention my self-induced buggy code. On the other hand, I'm getting MUCH better at debugging my code.
To make a very long story short:
Import the javax.swing package when you want to put a window on the computer screen.
JFrame is what makes a window to put your widget (button, text field, image, over a dozen different types) on.
An Event is what happens when the user does something with the screen widget (i.e. clicks a button.)
Each widget needs a Listener to tell the class that an event occurred.
Import java.awt.* when you want to use the java Graphics components for drawing, filling, setting colors, and manipulating those aspects of 2D drawing.
If you want more than one widget in a window, use Inner classes.
We created three versions of the midi player:
- The player gave a sound-only output of ascending piano notes.
- The player gave an output of ascending piano notes while printing "la" in the command window for each note that was played.
- A new window was created with a randomly placed rectangular box with randomly selected fill-color for each randomly selected piano note (64 times)
Yay! I'm finally creating graphics and sound! It's still a little foggy but it's a start!
0 comments:
Post a Comment