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 & HelpOther Libraries › G4P arteffact or other approach?
Page Index Toggle Pages: 1
G4P arteffact or other approach??? (Read 1459 times)
G4P arteffact or other approach???
Nov 5th, 2009, 9:00pm
 
  Hello. Just tried to put G4P elements into ArrayList wich was inside "void createWindows()" - now I can't to avoid the next. Just run the code with G4P library
Code:

import processing.opengl.*;
import guicomponents.*;
GTextField txf1, txf2, txf3;
GButton btnCopy12, btnCopy21;
GLabel lblLine1, lblLine2, lblLine3, lblLine4;
GPanel p;
GOption namess, percentss;
GOptionGroup  opgPlacetext;
GCheckbox shown, showp;
float vertical = 30;
boolean temp = false;
private GWindow window;
private int sx,sy,ex,ey;
private boolean done;
private GButton btnStart;
private GLabel lblInstr;
int arcs=2;
int segheight=15;
int segwidth = 50;
float percent1 = 3.6;
float percents = 50;
float makepercents=percent1*percents;
int showpercent =  floor(makepercents);
float[] newpercents = new float[arcs-1];

void setup(){
 size(400, 400, OPENGL);
 createWindows();
}
void draw() {
}

public void createWindows(){
 window = new GWindow(this, "Window ", 20, 20,300,500,false, JAVA2D);
 window.setBackground(0x12cdeb);
 window.addData(new MyWinData());
 window.addDrawHandler(this, "windowDraw");
 window.addMouseHandler(this, "windowMouse");
 p = new GPanel(this, "Toroid Control Panel", 20, 20, 270, floor(250+vertical*arcs));
 p.setAlpha(192);
 GComponent.globalColor = GCScheme.getColor(this,  GCScheme.BLUE_SCHEME);
 //GComponent.globalFont = GFont.getFont(this, "Georgia", 14);
 String s1 = "Mary had a little lamb it's fleece as white as snow";
 txf1 = new GTextField(this, s1, 80,30,50,15);
 txf2 = new GTextField(this, "Then the wolf appeared!",  80,60,50,0);
 txf3 = new GTextField(this, "",  190,60,50,0);
 // btnCopy12 = new GButton(this, "Copy 1 > 2", 40,100,100,20);
 //btnCopy21 = new GButton(this, "Copy 2 > 1", 150,100,100,20);
 lblLine1 = new GLabel(this, "Parts quantity", 10, 30, 100, 0);
 lblLine3 = new GLabel(this, "part 1 name", 10, 60, 80, 0);
 lblLine4 = new GLabel(this, "percent", 140, 60, 100, 0);
 lblLine1.setBorder(0);
 lblLine1.setBorder(0);
 lblLine2 = new GLabel(this, "", 10, 170, 100, 0);
 lblLine2.setBorder(1);
 lblLine2.setBorder(1);
 lblLine2.setOpaque(true);
 // line1 = "Parts number";
 opgPlacetext = new GOptionGroup();
 namess = new GOption(this, "Names", 85, floor(150+vertical*arcs),60);
 opgPlacetext.addOption(namess);
 percentss = new GOption(this, "Percent", 190, floor(150+vertical*arcs),60);
 opgPlacetext.addOption( percentss);
 shown = new GCheckbox(this,"Show names",85,floor(180+vertical*arcs),120);
 showp = new GCheckbox(this,"Show percent",190,floor(180+vertical*arcs),120);
 shown.setSelected(true);
 showp.setSelected(true);

 // The ArrayList
 ArrayList parts;
 parts = new ArrayList(arcs);
 for (int i = 5; i >= 0; i--) {  // i = parts.size()
   GTextField txf = new GTextField(this, "Then the wolf appeared!",  80,floor(i*vertical+60),50,0);
   parts.add(new  GTextField(this, "Then the wolf appeared!",  80,floor(i*vertical+60),50,0));
   p.add(txf);
 }

 p.add(txf1);
 p.add(txf2);
 p.add(txf3);
 p.add(btnCopy12);
 p.add(btnCopy21);
 p.add(lblLine1);
 p.add(lblLine2);
 p.add(lblLine3);
 p.add(lblLine4);
 p.add(namess);
 p.add(percentss);
 p.add(showp);
 p.add(shown);

 window.add(p);
}

class MyWinData extends GWinData {
 public int sx,sy,ex,ey;
 public boolean done;
}
Re: G4P arteffact or other approach???
Reply #1 - Nov 6th, 2009, 7:50am
 
Excuse me, but have you a question?
Also explaining what is G4P and where to find it could help. If that's a library, I can't find it in the Library page.
Now, if the question targets only the creator of G4P, I will just shut up.
Re: G4P arteffact or other approach???
Reply #2 - Nov 6th, 2009, 10:41am
 
 It is here http://www.lagers.org.uk/g4p/index.html   and here http://processing.org/reference/libraries/ - at GUIs place/   We've been talking about it some time ago, PhiLho  Smiley .
 I just don't know how to avoid that I have in the code, maybe that's my lack of foresight.
Re: G4P arteffact or other approach???
Reply #3 - Nov 6th, 2009, 11:28am
 
I have a bad memory... Smiley And for some reason, searching G4P on the library page a few hours ago (on another computer) gave no result.  Questioning

Oh well. I still don't understand the issue.
Re: G4P arteffact or other approach???
Reply #4 - Nov 6th, 2009, 11:43am
 
 I understand everything - I'm sorry. I'll try to paraphrase: "Could you give me a hint - why do  textfields of ArrayList, wich are declared and added to panel (panel.add(txf))  inside void createWindows() (ArrayList is also inside) appear  in both - GUI window and main 3D window.
Re: G4P arteffact or other approach???
Reply #5 - Nov 11th, 2009, 12:32pm
 
Sorry for not seeing this earlier but fortunately the solution is quite simple.

Before I give the solution I want to explain a little bit about how G4P works.

When you create a G4P component then it is automatically added to the main GUI window. If it is then added to the GPanel component the panel takes over control of the drawing of the component. When a GPanel (including added components) or another G4P component is added to a GWindow object then it is then drawn by the GWindow object.

So now to your code

Code:
  // The ArrayList
 ArrayList parts;
 parts = new ArrayList(arcs);
 for (int i = 5; i >= 0; i--) {  // i = parts.size()
   GTextField txf = new GTextField(this, "Then the wolf appeared!",  80,floor(i*vertical+60),50,0);
   parts.add(new  GTextField(this, "Then the wolf appeared!",  80,floor(i*vertical+60),50,0));
   p.add(txf);
 }

First you create a new GTextField called txf which is later added to the panel p which is later added to the GWindow window object - no problem.
The problem is in this line
Code:
parts.add(new  GTextField(this, "Then the wolf appeared!",  80,floor(i*vertical+60),50,0)); 



You are creating a NEW GTextfield object and since you are not adding this to the panel it will be drawn in the main GUI window.

The solution is
Code:
parts.add(txf); 

Cheesy

One final point the ArrayList parts is declared as a local variable in the createWindows() function so 'parts' will not be available outside ofthis method might want to make it global.
Smiley
Re: G4P arteffact or other approach???
Reply #6 - Nov 11th, 2009, 4:34pm
 
 Thank you! I see my mistake. I would like to ask 1 more resembling question: after running the following code I get this on my screen http://fotki.yandex.ru/users/al11al11/view/101372/?page=0
What did I miss, why does it happen?
Re: G4P arteffact or other approach???
Reply #7 - Nov 11th, 2009, 4:35pm
 
Code:
import guicomponents.*;
GTextField txf1, txf2, txf3, txf4, txf5, txf6, txf7, txf8, txf9, txf10, txf11;
GButton btnCopy12, btnCopy21;
GLabel dined1,dinea1, dinel2, Line13, Line14, Line15, Line16, Line17, Line18, Line19, l0blLine1, Line110, Line111, Linea1;
GPanel p;
GOption namess, percentss;
GOptionGroup  opgPlacetext;
GCheckbox shown, showp;


void setup() {
 size(1300,850);
 GComponent.globalColor = GCScheme.getColor(this,  GCScheme.BLUE_SCHEME);
 GComponent.globalFont = GFont.getFont(this, "PalatinoLinotype", 12);
 pushStyle();
 txf1 = new GTextField(this, "", 100,30,50,0);
 txf2 = new GTextField(this, "",  100,60,50,0);
 txf3 = new GTextField(this, "",  100,90,50,0);
 txf4 = new GTextField(this, "",  100,120,50,0);
 txf5 = new GTextField(this, "",  100,150,50,0);
 txf6 = new GTextField(this, "",  100,180,50,0);
 txf7 = new GTextField(this, "",  100,210,50,0);
 txf8 = new GTextField(this, "",  100,240,50,0);
 txf9 = new GTextField(this, "",  100,270,50,0);
 txf10 = new GTextField(this, "",  100,300,50,0);
 txf11 = new GTextField(this, "",  100,330,50,0);
 popStyle();

 dinea1 = new GLabel(this, "1", 15, 30, 100, 0);
 dined1 = new GLabel(this, "2", 15, 60, 100, 0);
 dinel2 = new GLabel(this, "Parts quantity", 15, 30+60, 100, 0);
 Line13 = new GLabel(this, "Parts quantity", 15, 60+60, 100, 0);
 Line14 = new GLabel(this, "Parts quantity", 15, 90+60, 100, 0);
 Line15 = new GLabel(this, "Parts quantity", 15, 120+60, 100, 0);
 Line16 = new GLabel(this, "Parts quantity", 15, 150+60, 100, 0);
 Line17 = new GLabel(this, "Parts quantity", 15, 180+60, 100, 0);
 opgPlacetext = new GOptionGroup();
 namess = new GOption(this, "Names", 85, 390,60);
 opgPlacetext.addOption(namess);
 percentss = new GOption(this, "Percent", 190, 390,60);
 opgPlacetext.addOption( percentss);
 shown = new GCheckbox(this,"Show names",85,420,50);
 showp = new GCheckbox(this,"Show percent",190,420,50);
 shown.setSelected(true);
 showp.setSelected(true);

p = new GPanel(this, "Toroid Control Panel", 5, 20, 390, 600);
 p.setAlpha(192);
 p.add(txf1);
 p.add(txf2);
 p.add(txf3);
 p.add(txf4);
 p.add(txf5);  
 p.add(txf6);
 p.add(txf7);
 p.add(txf8);
 p.add(txf9);
 p.add(txf10);
 p.add(txf11);
 p.add(btnCopy12);
 p.add(btnCopy21);
 p.add(Line13);
 p.add(Line14);
 p.add(Line15);
 p.add(Line16);
 p.add(Line17);
 p.add(Line18);
 p.add(Line19);
 p.add(Line110);
 p.add(Line111);
 p.add(namess);
 p.add(percentss);
 p.add(showp);
 p.add(shown);
}

void draw() {
 background(235,235,235);
}
Re: G4P arteffact or other approach???
Reply #8 - Nov 12th, 2009, 3:21am
 
You have not added the components to the panel you need to include

Code:
  p.add(dinea1);
 p.add(dined1);
 p.add(dinel2);


Also the line that creates the GOptionGroup does not work change it to this

Code:
  opgPlacetext = new GOptionGroup(this); 

Cheesy
Re: G4P arteffact or other approach???
Reply #9 - Nov 12th, 2009, 6:39am
 
 Oh, thank you very much!!! And I'm sorry, that was horrible from my part  Smiley
Page Index Toggle Pages: 1