Please send questions to
st10@humboldt.edu .
Random notes for CIS 480 - Advanced Java Programming, Week 2,
1-29-01
Topic: Java Applications, Part 1
* note: here is how you can modify your PATH on sorrel so that
you will use Java 1.2.2v7 instead of sorrel's default (Java 1.1.5).
Add it to the bottom of your .cshrc file, if desired:
setenv PATH /usr/opt/java122/bin:"$PATH"
* note: here is a statement that one could add to the bottom of
one's .cshrc file to cause the java command to look in
the current working directory as well as in your public_html/classes
directory for *.class files (substitute YOUR userid for YR_USERID):
setenv CLASSPATH "$CLASSPATH":/home/student/YR_USERID/public_html/classes:.
* see examples on course web page:
HelloWorld.java
ArgsPlay1.java
ArgsPlay3.java
GuiAppic1.java
(ManyButtons2.java is only there because we used
it to demo running an applet in BlueJ)
* an application without a graphic interface is pretty
straightforward, as seen in Flanagan, "Java Examples in a
Nutshell", 2nd edition, pp. 3-11, and in examples:
HelloWorld.java
ArgsPlay1.java
ArgsPlay3.java
* but: with graphic components?
* STARTING: Java Applications with GUI's (AWT version)
* from Deitel and Deitel, "Java How to Program", 3rd edition, p. 46:
"System.exit(0);
...is required in any application that displays a graphical user interface."
* an application with a GUI has to set up its own window, usually
using a Frame (in Java 1.1, AWT);
* see example, GuiApplic1.java
* (note that it does not close properly under BlueJ,
but does when run using the JDK)
* inner class: a class defined within another class
(called an outer class)
* advantage: this inner class can see the private
data fields of the outer class;
* whereas a lot of the main window "set-up" is done for you
in an applet, in an application you've got to take care of
it explicitly:
* needs to declare/instantiate a Frame (or a Frame
extension);
* note that a Frame's default layout is BorderLayout;
* you need to set the Frame's size, either by its setSize()
method or its pack() method;
* to make the Frame appear, you need to call its
show() method;
* note this handy anonymous inner class (from Morelli,
"Java, Java, Java", p. 487) for exiting the application
gracefully upon the occurrence of a windowClosing event on
the main Frame of the application:
mainFrame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
Note that this gives you the required System.exit(0); call for
your application-with-a-GUI, too.