Concurrent Programming with Java
Lab Manual, Version 1.0, F. Astha Ekadiyanto, 2002.

[Contents] [Next] [Previous]

Lab 3: Building Applets - Graphical representation


A Challenge Task

Once you have successfully compiled your Applet, you could try to run it again and see whether it works or not.

If your Applet is not working as planned (i.e. you cannot see the MobileStation moving when the Mouse is dragged or Clicked), then please check again your programming steps.

If it worked then:

CONGRATULATIONS!!!
Two Thumbs Up for you!!!
Well Done!!

Catch some breath and continue with this small Challenge.

Compare your Applet with the Applet introduced in the beginning of this Lab introduction. You will see the difference when your MobileStation is in the area of a Cell.
To make things clear, the difference is:
" Every time the mobile system is in coverage of a certain Cell/Rbs, the Rbs or Cell will appears differently as it is activated to serve the Mobile Station. The cell FillColor will change from background to YELLOW. Wouldn't it be nice to have such a display?"

It is up to you to accept this Challenge. Remember! The key is finding the correct Class to modify!

Hint:

Some Additional Tips:

Hybrid Class

You could actually construct an Application to run your Applet Class. Since an Applet Class is a subClass of a Panel Class, then when creating an Application, we can just treat the Applet Object as a Panel Container. By simply adding the Applet into a Frame Container, and make sure the code runs the Applet initialization (the init() method), you could immediately construct an Application. The Java code below can be used to define the main() method to run the Applet as an Application:

public static void main(String args[])
{
     Frame frame=new Frame("VisualMobileSystem");
     final VisualMobileSystem thePanel= new VisualMobileSystem();
     thePanel.init();
     frame.add(thePanel);
     frame.setSize(600,300);
     frame.addWindowListener(new WindowAdapter() 
		{
     		public void windowClosing(WindowEvent e) {
              thePanel.destroy();
     			System.exit(0);
     		}
     	}
	);
     frame.setVisible(true); 
} 

Distributing Application/Applet

To distribute your Application or Applet, you just simply provide all the *.class files compiled by javac.exe. You do not need to provide the *.java source file since most of the people only install the jre package to run java ByteCodes. When your Application/Applet consists of many classes, you might want to pack them into a single file to distribute. Java provide a packaging mechanism called Java ARchive (JAR).

JAR (Java ARchive) is a platform-independent file format that aggregates many files into one. Multiple Java applets and their requisite components (.class files, images and sounds) can be bundled in a JAR file and subsequently downloaded to a browser in a single HTTP transaction, greatly improving the download speed. The JAR format also supports compression, which reduces the file size, further improving the download time. In addition, the applet author can digitally sign individual entries in a JAR file to authenticate their origin. It is fully backward-compatible with existing applet code and is fully extensible.

BlueJ can be used to construct a JAR file. When you have finished compiling everything, you can just Export your Project into JAR by selecting the File - Export menu.

Then in the dialog window, select to Store as jar file. If there are application Classes in the Project, we can choose which main class to execute when the JAR file is read by Java Virtual Machine.

 

 

[Contents] [Next] [Previous]