Java: A platform for platforms
Sun's reorg may seem promising to shareholders but it's also a scramble for position. The question now is whether Sun can, or wants to, maintain its hold on Java technology. Especially with enterprise leaders like SpringSource and RedHat investing heavily in Java's future as a platform for platforms

Also see:

Discuss: Tim Bray on 'What Sun Should Do'

Featured Whitepapers
Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

Study guide: Tools of the trade, Part 3

Brush up on Java terms, learn tips and cautions, review homework assignments, and read answers to student questions

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone

Glossary of terms

installers
Installation programs.


panels
Installer windows.


splash screen
An introductory window that identifies the program being installed.


Tips and cautions

These tips and cautions will help you write better programs and save you from agonizing over why the compiler produces error messages.

Tips

  • InstallAnywhere provides various sample advertising billboard, background, and splash screen image files in its Graphics folder.
  • Complete the following steps for InstallAnywhere to enter the Advanced Designer instead of the Project Wizard from the startup window:

    1. Click the Preferences button on the startup window
    2. From the InstallAnywhere Preferences dialog box, select the Advanced Designer radio button in the InstallAnywhere Startup section of the General Settings tab
    3. Click the OK button


    The next time you start InstallAnywhere, its startup window takes you to the Advanced Designer.

  • To observe debug output for Windows installers, hold down the Ctrl key while the installer starts running.
  • Access the Advanced Designer from any Project Wizard window by clicking the Advanced Designer button at the bottom of that window.


Cautions

  • My Windows-based evaluation copy of InstallAnywhere 5 Standard Edition presented me with three problems:
    • My project folder did not always appear where I wanted it to appear: When I typed c:\Lines in the Save New Project As dialog box's Path text field, and the Folder dropdown list displayed any folder apart from the root folder, InstallAnywhere would not create my folder under the root folder. Instead, InstallAnywhere created that folder under the folder identified by the Folder dropdown list. I solved that problem by continuing to click the Up One Folder icon until I reached the root folder.
    • Advanced Designer uses the installer title and not the installer folder name: I consistently observed Graphical Lines Application instead of Lines as the installer folder name.
    • InstallAnywhere occasionally stopped responding: From time to time, my evaluation copy of InstallAnywhere 5 Standard Edition stopped responding (as evidenced in Windows task manager). I was forced to terminate the not-responding copy and start a fresh copy.
    You too might encounter these problems. (In fairness to Zero G, the problems might be related to my Windows platform.)


Homework

  • What is the purpose of InstallAnywhere's Web Installer applet?
  • Use the Advanced Designer to add a license agreement and your own billboard advertisement to the GLA.EXE installer.


Answers to last month's homework

Last month, I asked you to rewrite Lines.java to remove all static analysis violations. Here is my solution:

/**
 Lines.java
 */
import java.awt.*;
import java.applet.Applet;
/**
 Lines.class describes the Lines applet.
 @invariant
 */
public class Lines extends Applet implements Runnable
{
   private int width = 0, height = 0;
   private Thread runner = null;
   private final static int MAXCOLORS = 256;
   private final static int SLEEPMILLIS = 50;
   /**
    Initialize the applet.
    @pre
    @post
    */
   public void init ()
   {
      // Acquire the applet's width and height.
      width = getSize ().width;
      height = getSize ().height;
   }
   /**
    Start the applet.
    @pre
    @post
    */
   public void start ()
   {
      // If no thread exists, create a Thread object that associates with the
      // current Lines object, and start a new thread that invokes the current
      // Lines object's run() method.
      if (runner == null)
      {
          runner = new Thread (this);
          runner.start ();
      }
   }
   /**
    Paint the next animation frame.
    @pre
    @post
    @param
    */
   public void paint (Graphics g)
   {
      // Generate a random color and establish that color as the Graphics
      // context's drawing color.
      Color c = new Color (rnd (MAXCOLORS), rnd (MAXCOLORS), rnd (MAXCOLORS));
      g.setColor (c);
      // Generate a random set of coordinates in the upper-left quadrant of
      // the drawing surface, and use those coordinates as the starting
      // coordinates for a new line.
      int x1 = rnd (width / 2);
      int y1 = rnd (height / 2);
      // Compute the line's ending coordinates by mirroring the starting
      // coordinates in the lower-right quadrant.
      int x2 = width - x1;
      int y2 = height - y1;
      // Draw the line.
      g.drawLine (x1, y1, x2, y2);
      // Draw an inverse of the line (for symmetry).
      g.drawLine (x1, y2, x2, y1);
   }
   /**
    Return a random number from 0 through limit-1.
    @pre
    @post
    */
   static int rnd (int limit)
   {
      // Return a random integer that ranges from 0 through limit-1.
      return (int) (Math.random () * limit);
   }
   /**
    Run animation loop.
    @pre
    @post
    */
   public void run ()
   {
      // Obtain a reference to the thread that was started in the applet's
      // start() method.
      Thread current = Thread.currentThread ();
      // As long as runner contains the same reference, keep looping. The
      // reference in runner becomes null when the applet's stop() method
      // executes.
      while (current == runner)
      {
         // Invoke the paint(Graphics g) method to draw another
         // randomly-colored and randomly-positioned line.
         repaint ();
         // Pause for SLEEPMILLIS milliseconds to achieve an eye-pleasing
         // display.
         try
         {
             Thread.sleep (SLEEPMILLIS);
         }
         catch (InterruptedException e)
         {
             System.err.println ("Thread was interrupted.");
         }
      }
   }
   /**
    Stop the applet.
    @pre
    @post
    */
   public void stop ()
   {
      // Tell the line-drawing thread to terminate.
      runner = null;
   }
   /** The following method is overridden to prevent the drawing surface from
    being automatically cleared after a line is drawn. Stay tuned to Java
    101 to learn more about this method.
    @pre
    @post
    @param
    */
   public void update (Graphics g)
   {
      paint (g);
   }
}



Note the various Design by Contract tags (such as @pre). After solving initial static analysis violations, the absence of those tags led to additional violations. As you can see, I did not have to state actual contracts, just the tags. In practice, you should specify actual contracts (such as @pre g != null).

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources