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 & HelpPrograms › size of main tab with resizable window (napplet)
Page Index Toggle Pages: 1
size of main tab with resizable window (napplet) (Read 733 times)
size of main tab with resizable window (napplet)
May 25th, 2010, 11:35am
 
I'd like to have a main tab that contains two napplets.
The upper napplet has a height of 100 and a width like the main tab (is resizable). The under napplet should take the other space..

so we have a upper napplet "menu" with the height: 100 and the width: lastWidth and the under napplet "zeichnen" with the height: lastHeight- 100 and the width: lastWidth.. The problem is, that when I initialize lastWidth/lastHeight in the main tab, they have another "number" in the other tabs.. so how should I do, that I can resize the main window and the other change with it..?

MAIN TAB:
Code:
   
int lastWidth, lastHeight;
import napplet.*;
NAppletManager nappletManager;


void setup() {
size(600, 600);
nappletManager = new NAppletManager(this);
nappletManager.createNApplet("Menu", 0,0);
nappletManager.createNApplet("Zeichnen", 0,100);
frame.setResizable(true);
lastWidth = width;
lastHeight = height;
registerPre(this);
}

void pre(){
if(width != lastWidth || height != lastHeight){
int deltaX = transx - lastWidth/2;
int deltaY = transy - lastHeight/2;
transx = deltaX + width/2;
transy = deltaY + height/2;
lastWidth = width;
lastHeight = height;
}
}
void draw()
{ background(0);

}



MENU:
Code:
public class Menu extends NApplet {    

void setup() { registerPre(this);
size(100, 100);
}

void draw() {
background(0, 100, 0);
stroke(255); fill(255);
println(lastWidth);
println(lastHeight);
}

void pre(){
if(width != lastWidth || height != lastHeight){
int deltaX = transx - lastWidth/2;
int deltaY = transy - lastHeight/2;
transx = deltaX + width/2;
transy = deltaY + height/2;
lastWidth = width;
lastHeight = height;
}
}



}



and with the third tab (zeichnen) it should be the same, so it doesn't matter how the code looks...


thanks for every help!!
Re: size of main tab with resizable window (napplet)
Reply #1 - May 25th, 2010, 12:09pm
 
You should probably keep napplet-related questions in the napplet thread in the libraries forum.

Anyway, the napplet can access the parent through the parentPApplet field.  So, if your Menu napplet needed to access the parent's height field, that would be parentPApplet.height, the parent's width would be parentPApplet.width, etc.  This works for any field of the parent, so you could also access parentPApplet.mouseX for example, etc.

You can also access the parent's methods this way.  For example, the Menu napplet could draw a rectangle in the parent's space with parentPApplet.rect(), etc.
Page Index Toggle Pages: 1