9.3 OBJECT ORIENTED PROGRAMMING
ؕؓInheretance allows us to write one generic class (function) that depends on other functions to deal with special cases (this can be done in other languages with function calls, but this is more consistent)
an applet (note a special type of Java program) needs to have four functions,
* init() is always called first, and then start() and stop() will be called while the document using the applet is alive. If the document is exited, then stop() will be called if not already, and destroy() will be called last before exiting.
We can also call out to the parent HTML document. Generally, these calls deal with URL's and parameters.
Various types of media can also be included using simple functions.
Image getImage(URL) - will set up a link to an image at a remote site to be used when the image is drawn.
Image getImage(URL, filename) - an overloaded version that allows the filename string to be separated from the URL.
AudioClip getAudioClip(URL) - will retrieve (but not play yet) an audio file. Functions available include,
Applets can interact with the browser that has called it,
GUIs can be constructed using the `.awt' toolkit. This allows the user to work with a variety of interface tools. The hierarchy is shown below.
Component - the basic class to represent the position & size of objects
Container - a class that can hold other classes
Panel - container in a container for organizing objects
Window - a rectangular area on the GUI
Frame - a window with a border added
Dialog - will receive input from the user
FileDialog - a file selection box
Button - when clicked on with a mouse will cause an action
Canvas - an area generally for free form I/O like lines and mouse events
Checkbox - will allow toggled or checked inputs
List - a scrolling list of strings
Scrollbar - can be attached to canvases to scroll
TextArea - a text editing window
TextField - a single text inport line
Components, and all objects in the hierarchy, can use the following functions.
boolean mouseMove(Event e, int x, int y) - reports a move inside a component with no buttons pressed
boolean mouseDrag(Event e, int x, int y) - called when a mouse button is held down, and the pointer dragged inside a component
The container class also has a variety of associated functions (as well as its children)
Search for More: |
Custom Search
|   |