How can I make this a runnable .jar in Eclipse?

Here is a simple .pde written for Processing 2.2.1. Its just an example from the Tablet library with code that accesses the frame in Processing 2. I know about the exit() function, but that doesn't work when you turn it into an application in Processing, but the window listener does work. Besides, I need to access the frame for a menu and be able to record its location as well in my real program . This is just simple example to make a runnable jar with the things I need.

import g4p_controls.*;
import codeanticode.tablet.*;
import java.awt.*;
import java.awt.event.*;


Tablet tablet;

void setup() {
  size(640, 480);
  tablet = new Tablet(this);   
  frame.setResizable(true);
  frame.addWindowListener( new WindowAdapter(){
       public void windowClosing(WindowEvent e){
            int answer = G4P.selectOption(this, "BackupWork?", "BackupWork?", G4P.WARNING, G4P.YES_NO);
            if(answer == G4P.YES)
                     ;                              
          }
     });     
  background(0);
  stroke(255);  
}

void draw() {

  if (mousePressed) {
    strokeWeight(30 * tablet.getPressure());
    line(pmouseX, pmouseY, mouseX, mouseY);    
  }  
}

This works fine in processing 2.2.1 and behaves as expected. Turning this into an application in Processing2 generates this java source file:

import processing.core.*; 
import processing.data.*; 
import processing.event.*; 
import processing.opengl.*; 

import g4p_controls.*; 
import codeanticode.tablet.*; 
import java.awt.*; 
import java.awt.event.*; 

import java.util.HashMap; 
import java.util.ArrayList; 
import java.io.File; 
import java.io.BufferedReader; 
import java.io.PrintWriter; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.io.IOException; 

public class BasicDrawingExample2 extends PApplet {

Tablet tablet;

public void setup() {
  size(640, 480);
  tablet = new Tablet(this);   
//  frame.setResizable(true);
//  frame.addWindowListener( new WindowAdapter(){
//       public void windowClosing(WindowEvent e){
//            int answer = G4P.selectOption(this, "BackupWork?", "BackupWork?", G4P.WARNING, G4P.YES_NO);
//            if(answer == G4P.YES)
//                     ;                              
//          }
//    });     
  background(0);
  stroke(255);  
}

public void draw() {

  if (mousePressed) {
    strokeWeight(30 * tablet.getPressure());
    line(pmouseX, pmouseY, mouseX, mouseY);    
  }  
}
     static public void main(String[] passedArgs) {
          String[] appletArgs = new String[] { "BasicDrawingExample2" };
          if (passedArgs != null) {
            PApplet.main(concat(appletArgs, passedArgs));
          } else {
            PApplet.main(appletArgs);
          }
     }
}

I've had to comment out all references to "frame " because it gives a null pointer exception when I use this in a project in Eclipse. With that done, the program does work in Eclipse. I runs fine in an applet window and with the pen .dll copied into the project's binary folder, the pen pressure works. I can't access "frame" and I can't seem to make it a runnable jar. What am I doing wrong?

Tagged:

Answers

  • edited October 2016

    It would appear I am doomed to confine myself to the Processing 2.2.1 IDE. Thats the problem with magic. It resides in a box.

  • How come you never shifted to Processing 3?

  • edited November 2016

    For my purpose, the performance is not as good as processing 2.2.1 But as a far as my problem above, it was just a matter of running it as a java application in eclipse and not running it in the applet viewer. After doing so, I can access frame and make it a runnable jar.

  • Running it as an applet - that would be outdated if you were using Processing 3.

Sign In or Register to comment.