PScrollBar scrollbar;
PContainer screen;
void setup() {
//// put a scrollbar on the right side of the screen
scrollbar = new PScrollBar();
scrollbar.setBounds(width - 4, 0, 4, height);
//// let the container fill the rest of the screen
screen = new PContainer();
screen.scrolling = true;
screen.scrollbar = scrollbar;
screen.setBounds(0, 0, width - 4, height);
int y = 0;
PLabel label = new PLabel("Random 1");
label.calculateBounds(4, y, width - 12, PContainer.HEIGHT_UNBOUNDED);
screen.add(label);
y = label.y + label.height + 4;
int r1 = random(10);
PTextField textfield = new PTextField(Integer.toString(r1));
textfield.calculateBounds(4, y, width - 12, PContainer.HEIGHT_UNBOUNDED);
screen.add(textfield);
y = textfield.y + textfield.height + 8;
label = new PLabel("Random 2");
label.calculateBounds(4, y, width - 12, PContainer.HEIGHT_UNBOUNDED);
screen.add(label);
y = label.y + label.height + 4;
int r2 = random(10);
textfield = new PTextField(Integer.toString(r2));
// textfield.password = true;
textfield.calculateBounds(4, y, width - 12, PContainer.HEIGHT_UNBOUNDED);
screen.add(textfield);
int result = 0;
String s = "";
int o = random(1,4);
if(o == 1){
s = "+";
result = r1 + r2;
}
if(o == 2){
s = "-";
result = r1 - r2;
}
if(o == 3){
s = "*";
result = r1 * r2;
}
if(o == 4){
s = "/";
result = r1 / r2;
}
label = new PLabel("Operator");
label.calculateBounds(4, y+40, width - 12, PContainer.HEIGHT_UNBOUNDED);
screen.add(label);
y = label.y + label.height + 4;
textfield = new PTextField(s);
// textfield.password = true;
textfield.calculateBounds(4, y, width - 12, PContainer.HEIGHT_UNBOUNDED);
screen.add(textfield);
label = new PLabel("Answere");
label.calculateBounds(4, y+40, width - 12, PContainer.HEIGHT_UNBOUNDED);
screen.add(label);
y = label.y + label.height + 4;
textfield = new PTextField("");
// textfield.password = true;
textfield.calculateBounds(4, y, width - 12, PContainer.HEIGHT_UNBOUNDED);
screen.add(textfield);
label = new PLabel("Result");
label.calculateBounds(4, y+40, width - 12, PContainer.HEIGHT_UNBOUNDED);
screen.add(label);
y = label.y + label.height + 4;
textfield = new PTextField("");
// textfield.password = true;
textfield.calculateBounds(4, y, width - 12, PContainer.HEIGHT_UNBOUNDED);
screen.add(textfield);
//// initialize the container (which initializes
//// all of its children and the scrollbar)
screen.initialize();
screen.acceptFocus();
}
void draw() {
//// draw the container (which draws its children)
screen.draw();
}
void keyPressed() {
//// let the container handle the input, it will
//// pass it down to the focused child
screen.keyPressed();
}
void keyReleased() {
//// let the container handle the input, it will
//// pass it down to the focused child
screen.keyReleased();
}
PContainer screen;
void setup() {
//// put a scrollbar on the right side of the screen
scrollbar = new PScrollBar();
scrollbar.setBounds(width - 4, 0, 4, height);
//// let the container fill the rest of the screen
screen = new PContainer();
screen.scrolling = true;
screen.scrollbar = scrollbar;
screen.setBounds(0, 0, width - 4, height);
int y = 0;
PLabel label = new PLabel("Random 1");
label.calculateBounds(4, y, width - 12, PContainer.HEIGHT_UNBOUNDED);
screen.add(label);
y = label.y + label.height + 4;
int r1 = random(10);
PTextField textfield = new PTextField(Integer.toString(r1));
textfield.calculateBounds(4, y, width - 12, PContainer.HEIGHT_UNBOUNDED);
screen.add(textfield);
y = textfield.y + textfield.height + 8;
label = new PLabel("Random 2");
label.calculateBounds(4, y, width - 12, PContainer.HEIGHT_UNBOUNDED);
screen.add(label);
y = label.y + label.height + 4;
int r2 = random(10);
textfield = new PTextField(Integer.toString(r2));
// textfield.password = true;
textfield.calculateBounds(4, y, width - 12, PContainer.HEIGHT_UNBOUNDED);
screen.add(textfield);
int result = 0;
String s = "";
int o = random(1,4);
if(o == 1){
s = "+";
result = r1 + r2;
}
if(o == 2){
s = "-";
result = r1 - r2;
}
if(o == 3){
s = "*";
result = r1 * r2;
}
if(o == 4){
s = "/";
result = r1 / r2;
}
label = new PLabel("Operator");
label.calculateBounds(4, y+40, width - 12, PContainer.HEIGHT_UNBOUNDED);
screen.add(label);
y = label.y + label.height + 4;
textfield = new PTextField(s);
// textfield.password = true;
textfield.calculateBounds(4, y, width - 12, PContainer.HEIGHT_UNBOUNDED);
screen.add(textfield);
label = new PLabel("Answere");
label.calculateBounds(4, y+40, width - 12, PContainer.HEIGHT_UNBOUNDED);
screen.add(label);
y = label.y + label.height + 4;
textfield = new PTextField("");
// textfield.password = true;
textfield.calculateBounds(4, y, width - 12, PContainer.HEIGHT_UNBOUNDED);
screen.add(textfield);
label = new PLabel("Result");
label.calculateBounds(4, y+40, width - 12, PContainer.HEIGHT_UNBOUNDED);
screen.add(label);
y = label.y + label.height + 4;
textfield = new PTextField("");
// textfield.password = true;
textfield.calculateBounds(4, y, width - 12, PContainer.HEIGHT_UNBOUNDED);
screen.add(textfield);
//// initialize the container (which initializes
//// all of its children and the scrollbar)
screen.initialize();
screen.acceptFocus();
}
void draw() {
//// draw the container (which draws its children)
screen.draw();
}
void keyPressed() {
//// let the container handle the input, it will
//// pass it down to the focused child
screen.keyPressed();
}
void keyReleased() {
//// let the container handle the input, it will
//// pass it down to the focused child
screen.keyReleased();
}
No comments:
Post a Comment