5. Creation of a graphical output |
![]() |
5.2. The new class MyWorld
The Launcher class (in our case MyWorldLauncher.java) is always used to launch the application. Currently we start the application from a static main method within the application itself. This is a bad design. We want to implement an independent component that doesn’t know where it is called from. Therefore we create an additional class called “MyWorld”.
(1) Create a “MyWorld.java file” in the directory "org/resmedicinae/application/sample/myworld”. It is the same place where “MyWorldLauncher.java” is stored.
(2) Create a file and class header in the same way like we did it with the “MyWorldLauncher.java” file. Adapt the contents.
(3) Also import the following packages to our new file. The class belongs to the same package like the MyWorldLauncher class.
package org.resmedicinae.application.sample.myworld;
import java.lang.*; import org.resmedicinae.application.common.basic.*;
(4) Create the following empty class.
public class MyWorld extends BasicApplication{
}
Our class inherits from a class called BasicApplication. Classes inheriting from this class can be run standalone or belonging to a main (parent) application.
(5) We have to change the location of the application to be created in the “MyWorldLauncher.java” file. It is simply the new class MyWorld. "org.resmedicinae.application.sample.myworld.MyWorld"
(6) Now go back to the console and start the build process. As a result of these steps we have the same empty window.
<<PREVIOUS NEXT>> |
Contents of
MyworldLauncher.java Contents of Myworld.java
|
Copyright (c) 1999-2002. Dirk Behrendt All rights reserved. GNU FDL license. Last Update: 30.09.2002 |