Skip to content

Instantly share code, notes, and snippets.

@joshgiesbrecht
Created November 27, 2019 06:21
Show Gist options
  • Save joshgiesbrecht/b63e902cf99bdfce130f6deaa2aa594e to your computer and use it in GitHub Desktop.
Save joshgiesbrecht/b63e902cf99bdfce130f6deaa2aa594e to your computer and use it in GitHub Desktop.
import processing.core.PApplet;
public class UsingProcessing extends PApplet{
public static void main(String[] args) {
PApplet.main("UsingProcessing");
}
public void settings(){
size(300,300);
}
public void setup(){
fill(120,50,240);
}
public void draw(){
ellipse(width/2,height/2,second(),second());
}
}
@easye
Copy link

easye commented Nov 27, 2019

The Processing Core framework needs to extend the
processing.core.PApplet class for the applet.

Before I would work on getting that done, I would simply try to invoke
the main method to ensure you have everything linked correctly.

  ;; TODO execute the necessary code to get processing.core.PApplet in
  ;; memory
(require :abcl-contrib)
(require :jss)
(#"main" 'processing.core.PApplet)

Currently, the code to create synthetic Java interfaces is a lot more
mature than that to create synthetic Java classes, so I would look
around if you can somehow get by with an interface.

Use JAVA:JINTERFACE-IMPLEMENTATION to define an interface:

(require :jss)

(defun define-interface ()
  (jinterface-implementation
   "java.name.of.interface.this.implements"

   "settings"
   (#"size" 300 300)

   "setup"
   (#"fill" 120 50 240)

   "draw"
   (#"ellipse" (/ width 2) (/ height 2)
               (second) (second))))

To create a fully synthetic Java class in Lisp, use
JAVA:JNEW-RUNTIME-CLASS. Not all constructor patterns are supported,
but should be easily accommodated with a little elbow grease.

  (require :jss)

  (defun define-class ()
  (java:jnew-runtime-class
  "my.new.java.Applet"
  :superclass "processing.core.PApplet"
  :methods
  '(("settings" :void nil (lambda () (#"size" 300 300)))
  ("fill" :void nil (lambda () (#"fill" 120 50 240)))
  ("draw" :void nil (lambda ()  (#"ellipse" (/ width 2) (/ height 2)
                                                 (second) (second)))))))

I haven't tested this code with your problem. If you create a public
repository somewhere, I can help you patch things along.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment