C 12 HAPTER A Very Graphic Story

advertisement
CHAPTER 12
A Very Graphic Story
OVERVIEW
Simple GUI
 Getting User Input
 Creating a Listener
 ActionEvents
 Displaying Graphics
 Drawing
 Multiple Buttons
 Animation
 Example

SIMPLE GUI
Java using 'swing' for GUIs
 To display a GUI, you need to 'draw' a window,
add content, and display the window
 Example Chapter12

GETTING USER INPUT
User input is uncertain
 You don't want to wait all day for the user
 Creating a 'listener' helps handle this
 Listeners can be used for all type of input




Serial
Keyboard
Mouse
ACTIONEVENTS
We use the ActionEvents class to make listeners
 We need to re configure our code to handle this
 Then we will

Create an Action Listener object
 Link it to a button
 Make something happen when the Action Listener
reports on the button.

MULTIPLE BUTTONS (CHAPTER 13)
Java uses layout managers to place drawing
objects
 Common ones are:

BorderLayout
 FlowLayout
 BoxLayout


Lets start with FlowLayout
MULTIPLE LISTENERS
A simple way is to check the options in a single
Listener.
 This is not always the best way, but will work for
now
 Example

Download