View
212
Download
0
Embed Size (px)
Citation preview
Administrivia
P2 was due already If you’re not done yet:
Turn in what you can ASAP Decide whether you can really make
>= 15% improvement by tomorrow Spend real effort on P3
Administrivia
P3 stuff: Put serious work into design now -- will
save you big time/effort later G1 still needs to schedule their meeting
for tomorrow Available times: 10-11 AM, 2-3:30, 4:00-
5:00
Stuff I’m Looking for in P3M1
How will the game engine work? What classes/modules will there be? How will they communicate?
Exception hierarchy? What exceptions are possible? How are they arranged? Checked or uncheked?
Assembler/disassembler? How does it work? Parts? Will it share functionality w/ main game engine? How?
GUI: What will it look like? (Sketches are good) What does each part do? How do they communicate?
Multithreading? Who manages? Synchronization?
Swing, Swing, Swing...
The Model-View-Controller Pattern
Design principle for GUI apps (not the only principle!)
Separate the core data structures and logic (e.g., RVM; game rules) from the UI This is the “model”
Separate UI “input” (control) from “display” (view)
The Model-View-Controller Pattern
model
view controller
myAppClass
myAppData1
myAppData1
myAppData1
The Model-View-Controller Pattern
model
view controller
myAppClass
myAppData1
myAppData1
myAppData1
The Model-View-Controller Pattern
model
view controller
myAppClass
myAppData1
myAppData1
myAppData1
The Model-View-Controller Pattern
model
view controller
myAppClass
myAppData1
myAppData1
myAppData1
The Swing Component Model
The Swing Component Model
JFrame
The Swing Component Model
JFrame.getContentPane()
The Swing Component Model
JLabel
The Swing Component Model
JTabbedPane
The Swing Component Model
ButtonGroup (JRadioButtons)
The Swing Component Model
JButton
The Swing Component Model
JLabel
The Swing Component Model
JRadioButton
Assembling the GUI
All visual things in a Swing app are “components” (JComponent) Essentially, a component is something that
can be drawn on the screen May also be able to “contain” some other
component All components support an add() operation
Components nested inside other components
UI built hierarchically Create a top-level component (JFrame)
and recursively add parts to it
Assembling the GUI
JFrame
JLabel
JTabbedPane
JRadioButtongroup
JButton
JLabel
4
Arranging Stuff
How big should components be? Where should they be put relative to each
other? How do we get the JLabel on top of the JTabbedPane, beside the ButtonGroup, above the JButton...?
Swing uses a “layout manager” approach Instead of: “Make this thing 200 pixels
wide, starting at (x=150,y=35)” “Stack these things horizontally and flush
them all left” Use objects of type LayoutManager to control
Arranging Stuff
JFrame
JLabel
JTabbedPane
JRadioButton
JButton
JLabel
JPanel
JPanel
JPanel
verticalarrangement
verticalarrangement
horizontalarrangement
4 4
contentPane