We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › Two windows in pure java
Page Index Toggle Pages: 1
Two windows in pure java? (Read 3432 times)
Two windows in pure java?
Nov 27th, 2007, 8:58pm
 
hello, I know its not possible to launch two windows inside the processing language but i'm sure it is with pure java. does anyone have an example?
Re: Two windows in pure java?
Reply #1 - Nov 28th, 2007, 6:20am
 
hi. for example, you can add Swing frames easily :

Code:
javax.swing.JFrame frm = new javax.swing.JFrame();
frm.setSize(200, 200);
frm.setVisible(true);
Re: Two windows in pure java?
Reply #2 - Nov 28th, 2007, 11:21am
 
how can i draw stuff inside it? then i need java skills right?
Re: Two windows in pure java?
Reply #3 - Nov 28th, 2007, 3:56pm
 
I provide a detailed example of integrating Processing within Java here: http://www.friendsofed.com/extras/159059617X/Integrating-Processing-Within-Java.pdf
Re: Two windows in pure java?
Reply #4 - Nov 28th, 2007, 5:20pm
 
thanks ira, i'll look in to it!
Re: Two windows in pure java?
Reply #5 - Nov 30th, 2007, 8:32pm
 
perfect!!
i integrated it to run in xcode. now how do i draw inside a JFrame using the processing API?

Slm
Re: Two windows in pure java?
Reply #6 - Nov 30th, 2007, 9:25pm
 
Kontrol,

"...how do i draw inside a JFrame using the processing API? "

I cover that (in detail with code examples) in the chapter I mentioned.
Re: Two windows in pure java?
Reply #7 - Dec 1st, 2007, 1:14am
 
Beautiful!
I did it, thanks for the awesome help!

Slm
Re: Two windows in pure java?
Reply #8 - Dec 4th, 2007, 11:45pm
 
I am experiencing some problems. As i said i want to have a bunch of controls in one window and visuals in another. I need to access variables, slider pos etc., from the control window in the visuals window. Problem is i cant seem to access variables that "change" across classes without getting  nullPointerExeptions.
Can anyone explain how i build this concept?
Sojamo, you must know something about this?

thanks
Slm
Re: Two windows in pure java?
Reply #9 - Dec 6th, 2007, 12:38am
 
well, just make sure the variables have been filled up before accessing them.
For example, if you fill your variables in the setup()'s, make sure one PApplet has gone through setup() completely before accessing its variables from the other PApplets draw()-loop.

pseudo code:


boolean isSetUp = false;
void setup() {
  doHeavySetupStuff();
  isSetUp = true;
}

void draw() {
  if (otherSketch.isSetUp) {
        drawStuff();
  } else {
        justWait();
  }
}
Re: Two windows in pure java?
Reply #10 - Dec 6th, 2007, 5:59pm
 
problem is that one sketch doesnt registrate that isSetUp is changed if i dont put otherSketch.setup() in the first sketch. and that causes the nullPointerExeption
Re: Two windows in pure java?
Reply #11 - Dec 6th, 2007, 6:06pm
 
do you initialize both your sketches in the main class?
sketch1.init();
sketch2.init();

maybe some sourcecode would be helpful.
Re: Two windows in pure java?
Reply #12 - Jan 1st, 2008, 8:42pm
 
Ira wrote on Nov 30th, 2007, 9:25pm:
Kontrol,

"...how do i draw inside a JFrame using the processing API "

I cover that (in detail with code examples) in the chapter I mentioned.


Hi Ira,
I just wanted to let you know I bought your book because of the excerpt you quoted on this thread.  Thanks!
Myer Nore
Re: Two windows in pure java?
Reply #13 - Jan 18th, 2008, 7:33pm
 
I am so sorry I have been busy as hell.
Case is i have a class that I want to do some instances of, i want do draw them in one applet and access varibles in another.
So, i have what inside processing was an inner class.

Quote:



class slider {

 int sliderWidth = 50;
 int sliderHeight = 10;

 int sliderYMin;
 int sliderYMax;
 int TextSize = 26;

 boolean activeSlider = false;

 boolean sliderOver = false;
 int sliderOffsetX;
 int sliderOffsetY;
 boolean mouseSliderDown;

 PFont orator;

 int sliderX;
 int sliderY;
 
 String description;

 slider (int x, int y, int defaultY, int Max, String d) {  

   sliderX = x;
   sliderY = defaultY;

   description = d;

   sliderYMin = y;
   sliderYMax = Max;
   orator = loadFont("OratorStd-48.vlw");

   if(defaultY < y){
     print("Default y value exeeds the minimum y position.");
     exit();
   }

 }


 void updateMouse(int x, int y)
 {
   if ( overSlider(sliderX, sliderY, sliderWidth, sliderHeight) ) {
     sliderOver = true;

   }
   else {
     sliderOver = false;
   }
 }

 boolean overSlider(int x, int y, int width, int height)
 {
   if (mouseX >= x && mouseX <= x+width &&
     mouseY >= y && mouseY <= y+height) {
     return true;
   }
   else {
     return false;
   }
 }


 void update() {

   fill(255);
   smooth();
   textFont(orator);
   textSize(TextSize);
   text((sliderY-height+(height-sliderYMax))*-1,sliderX,sliderYMax+TextSize+5);
   textSize(12);
   text(description,sliderX,sliderYMax+TextSize+15,45,999);

   if(mouseSliderDown){
     sliderY= constrain(mouseY, sliderYMin+sliderOffsetY, sliderYMax+sliderOffsetY)-sliderOffsetY;
     activeSlider = true;
     
   }

   if((sliderOver) | (activeSlider)){

     fill(0,255,142);

   }

   else {
     fill(255);
   }

   noStroke();
   rect(sliderX, sliderY, sliderWidth, sliderHeight);


 }
 
 void pressed()
 {
   if(sliderOver){  
     sliderOffsetX = mouseX - sliderX;
     sliderOffsetY = mouseY - sliderY;

     mouseSliderDown = true;
   }
 }
 
 void released() {

   mouseSliderDown = false;
   activeSlider = false;
 }
 
}



As these are varibles that change, as it is a slider, i have  to put myObject.updateMouse(x,y) and myObject.Update() in the applet that draws the slider. If i do this class as an innerclass the this applet I cant seem to access them in other applet where i want to access the variable. If I do a public class i get nullPointerExeptions when putting myObject.updateMouse(x,y) and myObject.Update(). Basically i  need to be tld what to do.

I have a slider class that i want do draw i one app, and another app where i can access he varibles of the objects of the class.
Again sorry for the delay.

Re: Two windows in pure java?
Reply #14 - Jan 18th, 2008, 8:42pm
 
hi,
i guess the slider class should be public. then, best is to pass a reference to the drawing PApplet to the class:

public class slider{

  PAapplet parent;
  ...
  slider (PApplet parent, int x, int y, int defaultY, int Max, String d) {
  this.parent = parent;
     ...
  }
....
}

like this you don't have to "forward" the mouse updates but simply call parent.mouseX/parent.mouseY to get the mouse-coords. to draw something from within slider, use parent.fill(), parent.rect() etc.

then, make the variable holding the slider-object public.

public mySlider = new slider(this,......);

or if you keep your slider-instance private, create an access-method in your applet.. like:
public slider getSlider(int id) {
 return sliders[id];
}

then if your second PApplet knows about your first one, you can call the slider using something like
mainApplet.mySlider.update();
or if you use the access-method:
mainApplet.getSlider(42).update();

instead of forwading your update()-call to all slider-objects, you could also register a draw() method for the silder in slider construcor:
parent.registerDraw(this);
like this, if you have a method called "draw()" in slider, it is called whenever a draw() happens in the main applet.
Page Index Toggle Pages: 1