We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there, Im wondering if anyone could help me out real quick. Im making a programming involving a lot of custom buttons (+40). Im using java and netbeans to write the program, Im totally new to processing in general so If you could help me out itd be greatly appriciated. Im trying to make a separate class file that i can call to create a object (like a button for example). heres a sample:
File: WordDoc
import static java.lang.System.out;
public class WordDoc {
public static void RUN(String string) {
out.println(string);
}
}
This is the Main file to go with WordDoc.
File: Printer
public class Printer {
public static void main(String args[]) {
WordDoc.RUN("whatever you want to say");
}
}
That works just fine. whatever I put into the ( ) prints out when the program is run. What i need is to make something that would allow me to do this:
void draw() {
rect(4,4,4,4); //normal processing is in the file i want to call the button in.
ButtonClass.NewButton(X,Y,Width,Height,Color etc); // this is the line i need
How could I do this? I already tried this:
import processing.core.*;
public class Button extends InkWDStartwindow { //I dont know if that works, but it fixes errors raised by rect().
public static void Button(short X,short Y,short Wide,short Tall) {
public void draw() {
rect(X,Y,Wide,Tall);
}
}
Thanks Guys!
Answers
Sorry if the line formatting is weird... it was fine when i pasted it in
http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text
Fixed the line formatting.. could someone please help me with the posted question?
I don't understand your message at all. You show two classes, WordDoc and Printer, then you show ButtonClass.NewButton() which is unrelated to the first two, and remains unknown.
Normally, you create a new instance with the new keyword.
See also the tutorial Objects.
I used those two as a example... sorry about the confusion. I did get somewhere with this a second ago but its still having issues. Im no longer having errors but when I run the code it doesn't show the rectangle. it takes a distorted snapshot of my screen and fills the new processing window with it.
Why does the button class extend
InkWDStartwindow
and what is this class anyway? Also the button should not be created in the draw () method rather it should be created in the setup() method. Read this to find out about these 2 methodsit raises a error if i dont extend InkWDStartwindow, also doesnt recognize rect() or draw()
if i run it in setup() i get:
yet there are no errors in IDE until i run the file
extends
PApplet, preferably w/ methods setup() & draw() and other callbacks in it.Some of the big issues from your posted code. Let's debug it:
extends
PApplet. Correct!extends
InkWDStartwindow2, thus inheriting from PApplet too. Makes no much sense!So why InkWDStartwindow2 is OK and Button isn't if both are PApplet classes? :-/
Since you're coding in a Java-centric IDE (NetBeans), let's start w/ ordinary Java's style 1st:
import
it:And inside your InkWDStartwindow2 class, notice that it can directly call Processing's API, like size(), smooth(), fill(), etc., w/o any explicit PApplet reference, b/c it got its own canvas:
static
.p.println()
via the reference or directly PApplet.println()!Now for the Processing's style: :bz
public
classes as separate ".java" files, we can place them inside the PApplet class.static
nested classes, also called inner classes.Thanks so so much for the help! its very much appriciated. one question tho... how could I get things such as fill() and rectMode() to be included in Button?
The very same way Button can call rect() within its display() method.
Relying on the dot
.
access operator: http://processing.org/reference/dot.htmlVia a PApplet object reference, so it knows which "canvas" it's sending orders to: :-B
Although I think if all your Button objects got the same fill() & rectMode(), it's better defining them within setup()!
No need to waste CPU time telling the canvas over & over about those fixed configs! 8-X
Also... any ideas on how i could make a blank canvas inside a processing canvas. sorta like photoshop... a editing canvas inside the program canvas ( i hope that makes sense).
well i would do it in setup but this is just a test run. In the end i will have 40+ buttons with a different color and image for each.
like how would I, for instance, create a space inside my program that i could populate with images or buttons, that i can drag or transform, but the objects are only visible inside that space. sorta like a window It could be a rect().
Your new questions are way off the original problem. You should consider create another forum thread!
BtW, perhaps PGraphics is what you're looking for: http://processing.org/reference/PGraphics.html