A simple program with objects
in
Programming Questions
•
3 years ago
- import SpringGUI.*;
- SpringGUI gui;
- float w, va, v, a, pf;
- String name;
- void setup()
- {
- size(600,700);
- PFont font = loadFont("ArialMT-12.vlw");
- textFont(font);
- noSmooth();
- background(255,255,255);
- noFill();
- gui = new SpringGUI(this);
- gui.addTextField("appName","",50,50,60,20);
- gui.addTextField("realPower","",50,70,60,20);
- gui.addTextField("appPower","",50,90,60,20);
- gui.addTextField("voltage","",50,110,60,20);
- gui.addTextField("current","",50,130,60,20);
- gui.addTextField("powerFactor","",50,150,60,20);
- gui.addButton("addAppBtn","Add App",120,70,60,70);
- }
- void handleEvent(String[] p){
- if (p[1].equals("addAppBtn") && p[2].equals("mouseClicked")) {
- name = gui.getText("appName");
- w = float(gui.getText("realPower"));
- va = float(gui.getText("appPower"));
- v = float(gui.getText("voltage"));
- a = float(gui.getText("current"));
- pf = float(gui.getText("powerFactor"));
- App appName;
- appName = new App(w, va, v, a, pf);
- println(name);
- }
- }
- class App {
- App(float iw, float iva, float iv, float ia, float ipf) {
- float w = iw;
- float va = iva;
- float v = iv;
- float a = ia;
- float pf = ipf;
- }
- }
What I am trying to do is every time I press the addApp button I create a new app object with the different attributes.
I am not sure when each time I add an object how can I specify a new name of the object.
Thanks in advance!
1