Manuel
June 25, 2018, 10:07am
1
Hi, I’m using a .java file to contain an enum with extended variables an behaviours, but I want it to contain an object of one of the classes contained in a .pde file, however the compiler says that that class does not exist.
enums.java:
enum ECAM_Buttons
{
ECAM_Engines (0,0),
ECAM_Clr_R(5,2.2f);
float x_desfase_factor,y_desfase_factor;
static final int size = ECAM_Buttons.values().length;
Coordenada btn_desfase=new Coordenada(72, 50);
ECAM_Buttons(float xdes,float ydes){
this.x_desfase_factor = xdes;
this.y_desfase_factor = ydes;
}
// ECAM_Buttons(int xdes,int ydes){
// this.x_desfase_factor = float(xdes);
// this.y_desfase_factor = float(ydes);
// }
ECAM_Buttons(Number xdes,Number ydes){
this.x_desfase_factor = xdes.floatValue();
this.y_desfase_factor = ydes.floatValue();
}
}
coordenada.pde:
class Coordenada{
float x;
float y;
Coordenada(){
x=0;
y=0;
}
Coordenada(float _x){
x=_x;
y=0;
}
Coordenada(float _x,float _y){
x=_x;
y=_y;
}
Coordenada(Coordenada c){
x=c.x;
y=c.y;
}
}
I’m trying to do that because otherwise I can’t seem to get an Object of the class Coordenada within the enum, if there’s a better way to do so I’m here to learn
Thanks!
mat650
June 25, 2018, 10:54am
2
What about making your project a java project without the use of .pde files? Set processing as a library in your java project and extend the classes with PApplet.
Simplest solution is to change the extension “.pde” of the file “coordenada.pde” to “.java” as well.
You can also use Processing’s PVector as a replacement of your Coordenada class:
https://Processing.org/reference/PVector.html
“enums.java”:
import processing.core.PVector;
enum ECAM_Buttons {
ECAM_Engines(0, 0), ECAM_Clr_R(5, 2.2f);
static final int size = ECAM_Buttons.values().length;
final PVector btn_desfase = new PVector(72, 50);
float x_desfase_factor, y_desfase_factor;
ECAM_Buttons(float xdes, float ydes) {
x_desfase_factor = xdes;
y_desfase_factor = ydes;
}
}
Another replacement is Java’s Point2D.Float class:
https://Docs.Oracle.com/javase/10/docs/api/java/awt/geom/Point2D.Float.html
“enums.java”:
//import processing.core.PVector;
import java.awt.geom.Point2D;
enum ECAM_Buttons {
ECAM_Engines(0, 0), ECAM_Clr_R(5, 2.2f);
static final int size = ECAM_Buttons.values().length;
//final PVector btn_desfase = new PVector(72, 50);
final Point2D.Float btn_desfase = new Point2D.Float(72, 50);
float x_desfase_factor, y_desfase_factor;
ECAM_Buttons(float xdes, float ydes) {
x_desfase_factor = xdes;
y_desfase_factor = ydes;
}
}