Hey Everybody, Nooby here
I’m doing my first GUI and I don’t know how to save the Values in an ArrayList by pressing the Buttons
this is my Code so far:
import processing.core.PApplet;
import controlP5.*;
import processing.core.PFont;
import processing.core.PConstants;
public class ProcessingTest extends PApplet {
ControlP5 cp5;
int myColor = color(183, 174, 174);
float n, n1;
int w = 510;
int h = 800;
int x = 0;
public void settings()
{
size(w,h);
}
@Override
public void setup() {
PFont pfont1;
PFont.list();
pfont1 = createFont("Calvin", 40, true); // use true/false for smooth/no-smooth
ControlFont cfont = new ControlFont(pfont1, 40);
cp5 = new ControlP5(this);
// create a new button with name '9' / A
cp5.addButton("9")
.setValue(9)
.setPosition(260, 60)
.setSize(100, 100);
cp5.addButton("8")
.setValue(8)
.setPosition(150, 60)
.setSize(100, 100);
cp5.addButton("7")
.setValue(7)
.setPosition(40, 60)
.setSize(100, 100);
cp5.addButton("6")
.setValue(6)
.setPosition(260, 170)
.setSize(100, 100);
cp5.addButton("5")
.setValue(5)
.setPosition(150, 170)
.setSize(100, 100);
cp5.addButton("4")
.setValue(4)
.setPosition(40, 170)
.setSize(100, 100);
cp5.addButton("3")
.setValue(3)
.setPosition(260, 280)
.setSize(100, 100);
cp5.addButton("2")
.setValue(2)
.setPosition(150, 280)
.setSize(100, 100);
cp5.addButton("1")
.setValue(1)
.setPosition(40, 280)
.setSize(100, 100);
cp5.addButton("0")
.setValue(0)
.setPosition(150, 390)
.setSize(100, 100);
cp5.addButton("+")
.setValue('+')
.setPosition(370, 60)
.setSize(100, 100);
cp5.addButton("-")
.setValue('-')
.setPosition(370, 170)
.setSize(100, 100);
cp5.addButton("*")
.setValue('*')
.setPosition(370, 280)
.setSize(100, 100);
cp5.addButton("/")
.setValue('/')
.setPosition(370, 390)
.setSize(100, 100);
cp5.addButton("=")
.setValue('=')
.setPosition(260, 390)
.setSize(100, 100);
cp5.addButton(",")
.setValue(',')
.setPosition(40, 390)
.setSize(100, 100);
//
//
// change the font of the captionlabels
// for button created earlier.
cp5.getController("9")
.getCaptionLabel()
.setFont(cfont)
.toUpperCase(false)
.setSize(40)
;
cp5.getController("8")
.getCaptionLabel()
.setFont(cfont)
.toUpperCase(false)
.setSize(40)
;
cp5.getController("7")
.getCaptionLabel()
.setFont(cfont)
.toUpperCase(false)
.setSize(40)
;
cp5.getController("6")
.getCaptionLabel()
.setFont(cfont)
.toUpperCase(false)
.setSize(40)
;
cp5.getController("5")
.getCaptionLabel()
.setFont(cfont)
.toUpperCase(false)
.setSize(40)
;
cp5.getController("4")
.getCaptionLabel()
.setFont(cfont)
.toUpperCase(false)
.setSize(40)
;
cp5.getController("3")
.getCaptionLabel()
.setFont(cfont)
.toUpperCase(false)
.setSize(40)
;
cp5.getController("2")
.getCaptionLabel()
.setFont(cfont)
.toUpperCase(false)
.setSize(40)
;
cp5.getController("1")
.getCaptionLabel()
.setFont(cfont)
.toUpperCase(false)
.setSize(40)
;
cp5.getController("0")
.getCaptionLabel()
.setFont(cfont)
.toUpperCase(false)
.setSize(40)
;
cp5.getController("+")
.getCaptionLabel()
.setFont(cfont)
.toUpperCase(false)
.setSize(40)
;
cp5.getController("-")
.getCaptionLabel()
.setFont(cfont)
.toUpperCase(false)
.setSize(40)
;
cp5.getController("*")
.getCaptionLabel()
.setFont(cfont)
.toUpperCase(false)
.setSize(40)
;
cp5.getController("/")
.getCaptionLabel()
.setFont(cfont)
.toUpperCase(false)
.setSize(40)
;
cp5.getController("=")
.getCaptionLabel()
.setFont(cfont)
.toUpperCase(false)
.setSize(40)
;
cp5.getController(",")
.getCaptionLabel()
.setFont(cfont)
.toUpperCase(false)
.setSize(40)
;
}
@Override
public void draw() {
background(54, 57, 54);
stroke(106, 102, 100);
fill(70, 110, 157);
}
public static void main (String... args) {
ProcessingTest pt = new ProcessingTest();
PApplet.runSketch(new String[]{"ProcessingTest"}, pt);
controlP5.Button : String toString()
}
}
To be more precise , it will be al calculator so if I press Buttons “1” “+” “2” = I want to Save 1 1 2
→ I allredy have a nice class to translate the INT in a mathproblem and retun the result but the conection to my gui make me struggle
Thanks alot for your help in advance