CPS 1 - Spring, 2000 - Ramm 1/19/00 #3
- Announce
- Attendance Sheets (Last Round)
- Labs Start Tomorrow (Thursday)
- Read Course Pack Chapter 2
- First Quiz Today
2. An Introduction to Programming: Coding Decision Trees
- Heading for Java
- Book uses Pascal/Course Pack Represents Changes
- Ideas the same
- At lowest level, many similarities between Java & Pascal
- Pascal originally designed as a teaching language
- Read material in book and use Java guide
- Object Oriented Programming
- Treats everything as an Object
- Object has Data and Functions (Methods)
- Lawn mower Analogy
- Data: Location, Running, FuelLevel,
OilLevel, ThrottleSetting
- Methods: StartEngine, StopEngine, SetSpeed,
GoForward, GoBackward, TurnLeft, TurnRight
- Can go into much greater detail if desired
- Class Describes an Object in Java
- Two Ways of Using Java
- Stand Alone (like most traditional programs)
- Using Web as an Applet
- Will work with Applets in this Class
- Java Language
- Is simple and compact
- Smaller than C or C++
- However, for Practical Program
- Use many predefined Classes
- For effective use: experience
- Lots of grammar and detail
- Will have to memorize very little
- Understand and Know how to use
- Dump into the Water to Teach to Swim
- May be Bewildering at First
- Work with Examples
- Will seem Easy Later
- "Hello World" Demo
HelloWorld.java
HelloWorld.html
- Things to Note
- Program is a class
- Class contains data and methods
- Method init() always started for applets
- add statements (layout questions)
- Applet invoked through HTML file
- Program tested with Web Browser or appletviewer
- Demonstrate Use of Buttons
- Clicking on buttons can cause things to happen
- Triggers action method
- Button Use Demo
TrafficLight.java
TrafficLight.html
- Important Pieces:
- actionPerformed method
- events, cause
- if statements
- return statements