AdaPower Logged in as Guest
Ada Tools and Resources

Ada 95 Reference Manual
Ada Source Code Treasury
Bindings and Packages

Join >
Home >
Articles >
Getting Started >
Ada FAQ >
Source Treasury >
Books & Tutorials >
Packages for Reuse >
Latest Additions >
Ada Projects >
Press Releases >
Ada Audio / Video >
Home Pages >
Links >
Contact >
About >
Login >
Turing Ada JVM Applets in to Applications (David Botton)

Wouldn't it be great to turn those applets you are writing in Ada in to Applications also. The following code sample shows you how to add a main method to your Ada Applets so that they can be used as Applets or as Applications.
Package Specification
with java.applet.Applet; use java.applet.Applet;
with java.lang.String; use java.lang.String;
with; use;

package HelloWorld is
  type HelloWorld_Obj is new Applet_Obj with null record;
  type HelloWorld_Ptr is access all HelloWorld_Obj'Class;

  procedure paint(this : access HelloWorld_Obj; G : Graphics_Ptr);
  procedure main(Args : java.lang.String.String_Array);
end HelloWorld;

Package Body

with; use;
with java.awt.Frame; use java.awt.Frame;
with java.awt.Component; use java.awt.Component;

package body HelloWorld is

   procedure paint(this : access HelloWorld_Obj; G : Graphics_Ptr) is
      DrawString(G, +"Hello World!", x=>50, y=> 25);
   end paint;

   procedure main(Args : java.lang.String.String_Array) is
      Holder_Frame   : Frame_Ptr := new_Frame(+"My Ada Application");
      My_Applet      : HelloWorld_Ptr := new HelloWorld_Obj;
      cResult        : Component_Ptr;

      cResult := Add(Holder_Frame, +"Center", Component_Ptr(My_Applet));
      Resize(Holder_Frame, 200,75);
   end main;
end HelloWorld;

(c) 1998-2004 All Rights Reserved David Botton