|
Lab assignment 1 - A small button componentCheckinThe first thing to do is to register for the course. Log in at CSC and write in a terminal window:res checkin prutt10.
Each member in a lab group must register from his/her own account.
Now write
Optional-share directory with your lab partnerThe following (optional) command will create a common directoryprutt10 for you and your lab partner.
The labpartner must then log in and give the command with your login name
last. If you don't want a common directory, just create a directory
for the course, e.g.: The Sima queueing systemDuring a lab session, students will need help from lab assistants and/or wish to demonstrate their lab work for approval. Sima is the name of our computer program which manages a queue for this. After the commandcourse join prutt10, if you log out
and then log in again, sima is available as the short command
sm in a terminal window.
Otherwise, first write module add sima and then
sm. Sima will start in a separate window, displaying a
number of course abbreviations. Choose prutt and press
the Login-button. When you wish to queue for assistance from
a teacher, press the Queue-button.
Write a Java application and a Java applet!Connect to the directoryprutt10, create a subdirectory
lab1 and in lab1 create two java source code
files, where one must be an application that opens a window (Frame or JFrame)
and the other must be an applet to be shown in a web browser or with
appletviewer. The only thing required of these first programs is that they
display the name(s) of their author(s) in the window.
Remember that to run an applet, you need a html-file, e.g.
appletviewer Happ.htmlFirst time you use appletviewer it takes some time to start it but henceforth it will be faster than the browser. A minimal html-file may contain Happ.class (which is the
compiled version of Happ.java) in a window which is 300
pixels wide and 150 pixels high.
Create an extended button with different statesMake a class for a new grafic component which is an extension of (inherits from) one of the classesButton or JButton. The new
component must have at least two different states. One click on
the button must change its state and the change must be visible
on the button. At least two visible changes must be present, e.g.
colour and text. You may choose to have n different states,
in which case n button clicks must bring you back to the initial
state. Important: Please note that the button component must manage
its states by itself! The surrounding program (applet or application)
is only a host for the component, without interfering with it.
It is nice but not required that a user can choose the appearance of
the states through parameters to the constructor of the button:
new MyButton(Color.white, Color.cyan, "On", "Off"); new MyButton(Color.green, Color.red, "Drive", "Stop");The two states of each object are shown as different colours and different texts, chosen on creation of the buttons. Buttons in windowsAdd objects of the new extended button in the application and in the applet. To emphasize the self-contained nature of the objects, put more than one object in a window and observe their different independent states.A package for the button classFinally, put the code of the new component in a subdirectorymyPackage and add the proper lines to all java files
so that the application and the applet both use the component
from the package myPackage (you may of course use any
name of you choice for the package!).
Draw a UML class diagramfor the component, applet and application. All classes used (new and from libraries) must be represented in the diagram but it is sufficient to show only the class names and no internal details.Lab demonstration
When the teacher approves, ask for his/her
signature on your personal signature sheet!
Published by: <ann@nada.kth.se>
|