CP2003 - Tutorial Twelve: Applet of My Eye
For the twelth and final tutorial we are going to firstly look at some
summary questions and then take a look at applets
and how easy it is to make an applet out of an application.
- Firstly, some quick questions harking back to your early days of CP2003:
- What is the difference between a class and an object?
- What is inheritance and how does Java implement it? Draw a hierarchy
scheme for various bank accounts (savings account, cheque account, credit
account, passbook account etc.).
- What is the point of Java forcing you to use try/catch blocks?
- What is the point of Java wrapping lots of objects around each other
when you are (say) trying to read a file?
- What are access modifiers (public, private, protected) and what part do
these play in inheritance?
- The programming question for today is firstly to consider an already
existing application (start with something slightly simpler like BallMover.java - don't forget to download the picture for the dialog box).
- The task now is to convert BallMover.java into an applet. There
is a standard way of doing this: Firstly, you will need to use the class
JApplet which is like a plain Applet but has its
own content pane and a few other niceties. Here's what else you have to do:
- Remove the class with the main method in it.
- Inherit from JApplet, not JFrame.
- Remove the window listener.
- Remove the call to setSize and instead set the size in the
applet's HTML page.
- Remove the call to setTitle.
- Compile your modified code.
- You'll need to write an accompanying HTML file (like the one in
tutorial nine), and you should point your browser at this HTML file. Note
that if the browser you are using is not a very recent version then you
should use the program appletviewer which comes with the jdk
(run it as appletviewer blah.html).
- If you make it this far, you might want to try to make your second
assignment into an applet.
Copyright © 2000. James Cook University. All rights reserved.