5. Creation of a graphical output Table of contents

5.1. An empty window

 

 

At this point we want to create a simple graphical output, an empty window. Therefore we have

to update our “MyWorldLauncher.java” file. You can maintain the file and class header.

 

(1) Add this import statement. We will need some classes which are stored in this package.

import org.resmedicinae.application.common.main.*;

 

(2) Create the following code.

 

public static void main(String[] args) {

 

try

{

 ApplicationRunner r = new ApplicationRunner();

 

 if (r != null)

 {

  r.createApplication("org.resmedicinae.application.common.basic.BasicApplication",args,null);

 

 }

  else

  {

   throw new NullPointerException("Could not run component. The application runner is null.");

  }

 }

  catch (Exception e)

  {

   System.out.println("Could not launch application. Undiscovered exception:\n");

   e.printStackTrace();

  }

 

The class ApplicationRunner represents an application runner. Its only task is to start up and shutdown an application.

 

With the following line you create an instance of the class ApplicationRunner.

ApplicationRunner r = new ApplicationRunner();

 

Before you can use methods or variables of the created object, you always have to check whether the object is unequal NULL. Otherwise you have to throw a new exception.

 

if (r != null)

 { ....  }

  else

  {

   throw new NullPointerException("Could not run component.The application runner is null.");

  }

  

 

The method createApplication() of the parent class of ApplicationRunner creates the application. 

You have to turn over the location of the application to be created. In a first step it is simply the class BasicApplication. Classes inheriting from this class can be run standalone or belonging to a main (parent) application.

"org.resmedicinae.application.common.basic.BasicApplication"

 

Unalterable is a try-catch block that encloses the code to catch eventual exceptions that may occur when running the system.

 

The method printStackTrace() prints an extract of the runtime stack.

 

Use the link "Contents of MyworldLauncher.java" on the right side to look the file.

(3) If you have done the changes go back to the console an compile our file by typing “build.bat”. If there are no mistakes you should see a simple empty window. It is provided by the Res Medicinae framework.

 

 <<PREVIOUS                                                                   NEXT>>

Contents of MyworldLauncher.java
Copyright (c) 1999-2002. Dirk Behrendt All rights reserved. GNU FDL license. Last Update: 30.09.2002