Write Applet with FPC JVM

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Write Applet with FPC JVM

Ingemar Ragnemalm

Hello, FPC list!

Is there anyone who knows how to write a JVM applet with FPC?

I have this minimal Java applet:

import java.applet.*;

import java.awt.*;

public class HelloWorldApplet extends Applet

{

    public void paint (Graphics g)

    {

       g.drawString ("Hello World", 25, 50);

    }

}


AFAIK this translates to:

{$mode objfpc}

// I try to make an Applet. How?

program HelloWorldAppletProgram;

uses

     jdk15;

type

     HelloWorldApplet = class(JAApplet)

     public

         procedure paint(g: JAGraphics);override;

     end;

     

     procedure HelloWorldApplet.paint(g: JAGraphics);

     begin

         g.drawString('Hello World (FPC)',25,50);

     end;

begin

end.


Compiles, produces HelloWorldAppletProgram.class and HelloWorldApplet.class.

FPC compilation line:

/usr/local/bin/ppcjvm -O2 -g HelloWorldAppletProgram.pas -XP
-FD/usr/local/bin/

Java compilation line:

/usr/bin/javac HelloWorldApplet.java

Uses this HTML file:

<title>HelloWorldApplet</title><hr>
<applet archive="AppletClasses.jar" code="HelloWorldApplet.class"
width=200 height=200></applet>


Should IMHO run with

appletviewer HelloWorldApplet.html

It compiles with both Java and FPC, but the FPC version doesn't run.

Any ideas? Any obvious mistakes of mine?


/Ingemar

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Write Applet with FPC JVM

leledumbo
Administrator
> It compiles with both Java and FPC, but the FPC version doesn't run.

Works fine here:
fpc-helloworld-applet.png

> Any ideas? Any obvious mistakes of mine?

I change your program to a unit, though I don't think that matters as long as HelloWorldApplet.class is generated. Then I modify your applet tag by removing archive attribute as it's not in a .jar but a standalone .class. That's it.
Reply | Threaded
Open this post in threaded view
|

Re: Write Applet with FPC JVM

Ingemar Ragnemalm
In reply to this post by Ingemar Ragnemalm

> Message: 1
> Date: Sat, 2 Apr 2016 03:39:41 -0700 (MST)
> From: leledumbo <[hidden email]>
> To: [hidden email]
> Subject: Re: [fpc-pascal] Write Applet with FPC JVM
> Message-ID: <[hidden email]>
> Content-Type: text/plain; charset=us-ascii
>
>> It compiles with both Java and FPC, but the FPC version doesn't run.
> Works fine here:
> fpc-helloworld-applet.png
> <http://free-pascal-general.1045716.n5.nabble.com/file/n5724733/fpc-helloworld-applet.png>
>
>> Any ideas? Any obvious mistakes of mine?
> I change your program to a unit, though I don't think that matters as long
> as HelloWorldApplet.class is generated. Then I modify your applet tag by
> removing archive attribute as it's not in a .jar but a standalone .class.
> That's it.

Great! I tried and indeed, compiling a unit did it! Editing the HTML
file didn't seem to matter though.


/Ingemar

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal