Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-04

Write Applet with FPC JVM

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

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

Reply by email

leledumbo
to Ingemar Ragnemalm
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.

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Write-Applet-with-FPC-JVM-tp5724727p5724733.html Sent from the Free Pascal - General mailing list .

Reply by email

Ingemar Ragnemalm
Show quoted text 18 lines
Message: 1 Date: Sat, 2 Apr 2016 03:39:41 -0700 (MST) From: leledumbo To: Subject: Re: [fpc-pascal] Write Applet with FPC JVM Message-ID: 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

Reply by email