» codelab : http://codelab.fr/accueil » Forum : Processing : http://codelab.fr/processing » HELP URGENT SVP Créer un lien entre fenêtre et bouton : http://codelab.fr/5009 Ceci est la version imprimable d'un sujet du forum, pour retourner à la version complète : HELP URGENT SVP Créer un lien entre fenêtre et bouton |
Miaou — 2014-05-13 20:23:44 |
Salut! ControlFrame addControlFrame(String theName, int theWidth, int theHeight) { Cependant, j'ai essayer de placer partout if(option==true)==> f.show() mais soit on me dit f n'existe pas soit il y a une erreur mais donc je ne sais pas comment faire. |
Mushussu — 2014-05-14 07:50:45 |
Bonjour, /** * ControlP5 Controlframe * with controlP5 2.0 all java.awt dependencies have been removed * as a consequence the option to display controllers in a separate * window had to be removed as well. * this example shows you how to create a java.awt.frame and use controlP5 * * by Andreas Schlegel, 2012 * www.sojamo.de/libraries/controlp5 * */ import java.awt.Frame; import java.awt.BorderLayout; import controlP5.*; private ControlP5 cp5; ControlFrame cf; Frame f; int def; void setup() { size(400, 400); cp5 = new ControlP5(this); // by calling function addControlFrame() a // new frame is created and an instance of class // ControlFrame is instanziated. cf = addControlFrame("extra", 200, 200); // add Controllers to the 'extra' Frame inside // the ControlFrame class setup() method below. cp5.addToggle("fenetre") .setPosition(40, 100) .setSize(50, 20) ; } void draw() { background(def); } ControlFrame addControlFrame(String theName, int theWidth, int theHeight) { f = new Frame(theName); ControlFrame p = new ControlFrame(this, theWidth, theHeight); f.add(p); p.init(); f.setTitle(theName); f.setSize(p.w, p.h); f.setLocation(100, 100); f.setResizable(false); f.setVisible(false); return p; } void fenetre(boolean e) { f.setVisible(e); } // the ControlFrame class extends PApplet, so we // are creating a new processing applet inside a // new frame with a controlP5 object loaded public class ControlFrame extends PApplet { int w, h; int abc = 100; public void setup() { size(w, h); frameRate(25); cp5 = new ControlP5(this); cp5.addSlider("abc").setRange(0, 255).setPosition(10, 10); cp5.addSlider("def").plugTo(parent, "def").setRange(0, 255).setPosition(10, 30); } public void draw() { background(abc); } private ControlFrame() { } public ControlFrame(Object theParent, int theWidth, int theHeight) { parent = theParent; w = theWidth; h = theHeight; } public ControlP5 control() { return cp5; } ControlP5 cp5; Object parent; } |
Miaou — 2014-05-14 18:31:41 |
le code ne marche pas. Il me donne cette erreur: nullerpointException. De plus, si tu as créer e. Comment je fais pour le mettre true ou false? par exemple en fonction d'un autre booléen ou dans groupEvent du bouton |
Olivier — 2014-05-14 19:05:52 |
Ce code fonctionne parfaitement chez moi sous Ubuntu 14.04 + Processing 2.1.2 |
Miaou — 2014-05-14 19:14:57 |
Très bien, pardon. Est-ce qu'il existe un autre moyen? ^^ Je suis sous Processing 2.1.1 mais je ne souhaite pas le mettre à jour dû à la version du lycée. |
Mushussu — 2014-05-15 08:07:24 |
Voilà, comment l'utiliser avec un bouton et un controlEvent(). Concernant ton problème, comme tu ne le précise pas je suppose que tu es sous Windows, peut-être mettre à jour java ! Mais sans certitude aucune. import java.awt.Frame; import java.awt.BorderLayout; import controlP5.*; private ControlP5 cp5; ControlFrame cf; Frame f; int def; void setup() { size(400, 400); cp5 = new ControlP5(this); // by calling function addControlFrame() a // new frame is created and an instance of class // ControlFrame is instanziated. cf = addControlFrame("extra", 200, 200); // add Controllers to the 'extra' Frame inside // the ControlFrame class setup() method below. cp5.addButton("bouton") .setPosition(100, 100) .setSize(50, 19) ; } void draw() { background(def); } public void controlEvent(ControlEvent theEvent) { if (theEvent.getController().getName().equals("bouton")) { f.setVisible(!f.isShowing()); } } ControlFrame addControlFrame(String theName, int theWidth, int theHeight) { f = new Frame(theName); ControlFrame p = new ControlFrame(this, theWidth, theHeight); f.add(p); p.init(); f.setTitle(theName); f.setSize(p.w, p.h); f.setLocation(100, 100); f.setResizable(false); f.setVisible(false); return p; } // the ControlFrame class extends PApplet, so we // are creating a new processing applet inside a // new frame with a controlP5 object loaded public class ControlFrame extends PApplet { int w, h; int abc = 100; public void setup() { size(w, h); frameRate(25); cp5 = new ControlP5(this); cp5.addSlider("abc").setRange(0, 255).setPosition(10, 10); cp5.addSlider("def").plugTo(parent, "def").setRange(0, 255).setPosition(10, 30); } public void draw() { background(abc); } private ControlFrame() { } public ControlFrame(Object theParent, int theWidth, int theHeight) { parent = theParent; w = theWidth; h = theHeight; } public ControlP5 control() { return cp5; } ControlP5 cp5; Object parent; } |
Miaou — 2014-05-15 22:08:51 |
Ca marche, merci beaucoup pour votre aide :) ! public ControlFrame(Object theParent, int theWidth, int theHeight) { parent = theParent; w = theWidth; h = theHeight; } public ControlP5 control() { return cp5; } car je ne vois pas son utilité |