Upload
edgar-potter
View
212
Download
0
Embed Size (px)
Citation preview
University of Utah – School of Computing
University
of Utah
22
Methods
• Every method must be called before it can do anything
• Two ways it can be called- By Java (automatically)- By the programmer (explicitly)
University of Utah – School of Computing
University
of Utah
33
Methods
• Automatically called methods- init()- paint()- actionPerformed()
University of Utah – School of Computing
University
of Utah
44
Methods
• Manually called methods- JPanel.add(button) // or whatever
- Integer.parseInt()- Math.random()- JTextField.getText()
University of Utah – School of Computing
University
of Utah
55
Methods
• (show example on whiteboard)
University of Utah – School of Computing
University
of Utah
66
Applets: A Review
• Run inside a web browser
• Extend JApplet
• Don't control their own size
University of Utah – School of Computing
University
of Utah
77
Java Applications
• Run in their own window- (or no window at all!)
• Don't have to "extend" anything- (but most do, anyway)
• Can set their own window size!
University of Utah – School of Computing
University
of Utah
99
Application Example
• Homework 4 as an application- (show demo)
University of Utah – School of Computing
University
of Utah
1010
A Recipe for Applets
• Extend JApplet• Write init() and/or paint() method• Tell Eclipse (or a web page) how big to
make it
University of Utah – School of Computing
University
of Utah
1111
A Recipe for Applications
• Extend JFrame to give us a window• Write a main() method• Tell application:
- How big to make the window- To open the window- What to do when the window closes
University of Utah – School of Computing
University
of Utah
1212
More on methods
• Applets told us what methods to write• Applications don't, except main().• What to do?
- Put all our code inside main()?- Make up our own brand new methods?
University of Utah – School of Computing
University
of Utah
1313
More on methods
• We can write our own methods!• Then it's up to us to call them.
- Java won't call them automatically