Eclipse Scope issue
in
Integration and Hardware
•
1 year ago
Hi everyone, I home someone here can point out what I am missing. I have written 2 processing applets that can control led cubes ( youtube ledcube if you aren't familiar with them ) , and am trying to combine them into one java application. I have been trying test if this is possible for the past week and am completely stuck. I don't know if this is the best place to post this, but I figure people in the java forums might just complain about the differences between processing and java. I figured I'd try here first.
Here is what I am doing:
//=================================================
//=================================================
//=================================================
//=================================================
I have two applets (Applet1 and Applet2) inside Frames (Frame1, Frame2) a circle class and my main class. The problem is that the Circle Object created in the main class is out of scope in regards to the applets. I have tried using java's clonable, writing my own copyable method and even overwriting the Circle object, but it will not compile. Any refrence to the main circle object "
aNewCircle" is highlighted because it is an unknown variable.
My goal is to have two applets each drawing the same circle. Changing the color or position attribute of an circle in one applet should instantly show the same change in the other applet.
I have tried every scope imaginable for aNewCircle. static, public, protected ect..
I am using proclipsing
http://code.google.com/p/proclipsing/
I have completely exhausted all my java books and google on this issue, any tips would be helpful.
- package ellipseproblem;
- public class Applet1 extends processing.core.PApplet
- {
- Circle aGreenCircle;
- public void setup()
- {
- background(255,0,0);
- aGreenCircle = new Circle();
- }
- public void draw()
- {
- background(255,0,0);
- aGreenCircle.display(this);
- }
- public void mouseReleased()
- {
- aGreenCircle.setXLocation(100);
- }
- }
//=================================================
- package ellipseproblem;
- public class Applet2 extends processing.core.PApplet
- {
- //public Circle aGreenCircle;
- Circle aGreenCircle = new Circle();
- //Circle aGreenCircle = aNewCircle;
- public void setup()
- {
- background(0,0,255);
- aGreenCircle = new Circle();
- }
- public void draw()
- {
- background(0,0,255);
- aGreenCircle.display(this);
- //aNewCircle.display(this);
- }
- public void mouseReleased()
- {
- aGreenCircle.setXLocation(100);
- }
- }
//=================================================
- package ellipseproblem;
- public class Frame1 extends java.awt.Frame
- {
- Applet1 anApplet1;
- Frame1()
- {
- setBounds (0,0, 300, 300);
- anApplet1 = new Applet1();
- add(anApplet1);
- anApplet1.init();
- show();
- }
- }
//=================================================
- package ellipseproblem;
- public class Frame2 extends java.awt.Frame
- {
- Applet2 anApplet2;
- Frame2()
- {
- setBounds (0,400, 400, 400);
- anApplet2 = new Applet2();
- add(anApplet2);
- anApplet2.init();
- show();
- }
- }
//=================================================
- package ellipseproblem;
- import processing.core.PApplet;
- public class EllipseProblem extends PApplet
- {
- // Frame1 aFrame1;
- // Frame2 aFrame2;
- Applet1 anApplet1;
- Applet2 anApplet2;
- public static Circle aNewCircle;
- public void draw()
- {
- anApplet1.redraw();
- anApplet2.redraw();
- }
- public static void createGui()
- {
- Frame1 aFrame1 = new Frame1();
- Frame2 aFrame2 = new Frame2();
- aFrame1.setVisible( true );//not needed
- }
- public static void main(String _args[])
- {
- PApplet.main(new String[] { ellipseproblem.EllipseProblem.class.getName() });
- createGui();
- aNewCircle = new Circle();
- }
- }
1