AdaPower Logged in as Guest
Ada Tools and Resources

Ada 95 Reference Manual
Ada Source Code Treasury
Bindings and Packages
Ada FAQ


Join >
Articles >
Ada FAQ >
Getting Started >
Home >
Books & Tutorials >
Source Treasury >
Packages for Reuse >
Latest Additions >
Ada Projects >
Press Releases >
Ada Audio / Video >
Home Pages >
Links >
Contact >
About >
Login >
Back
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 java.awt.graphics; use java.awt.graphics;

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 interfaces.java; use interfaces.java;
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
   begin
      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;
   begin
      Init(My_Applet);
      Start(My_Applet);

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


(c) 1998-2004 All Rights Reserved David Botton