-1

controlP5処理 GUIを使用しており、draw()関数内にカウンターが必要です。

draw()関数が継続的に実行され、すべての for ループが最後のステップに表示されることを知っています。

私はすべてのステップを見る必要があります。2 つの入力がありますが、1 回しか入力できませんdraw()draw()入力を待つ機能などが必要です。

import controlP5.*;

Textarea myTextareaMI;
Textarea myTextareaVI;
Textarea my;

String textValueBODOVI = "";
String textValueZVANJE = "";
boolean mi=false, vi=false;
int i=1;


ControlP5 cp5;

int myColor = color(255);

int c1, c2;

float n, n1;



void setup() {
  size(320, 480);
  noStroke();
  PFont font = createFont("arial", 20);
  cp5 = new ControlP5(this);
  cp5.addButton("NOVA PARTIJA")
    .setValue(0)
      .setPosition(0, 0)
        .setSize(480, 19)
          ;
  cp5.addButton("PONISTI ZADNJI UNOS")
    .setValue(100)
      .setPosition(0, 20)
        .setSize(480, 19)
          ;

  cp5.addBang("MI")
      .setPosition(60, 80)
        .setSize(60, 20)
          .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)


            ;
  cp5.addBang("VI")
      .setPosition(123, 80)
        .setSize(60, 20)
          .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)


            ;
  cp5.addTextfield("BODOVI")
    .setPosition(60, 41)
      .setSize(60, 20)
        .setFont(font)
            .setColor(color(255, 0, 0))
              ;
  cp5.addTextfield("ZVANJE")
    .setPosition(123, 41)
      .setSize(60, 20)
        .setFont(font)
            .setColor(color(255, 0, 0))
              ;


  ;
  int l=0;
  for (int i=1;i<11;i++,l=l+22) {
    my = cp5.addTextarea("MIVI"+i).setPosition(60, 101+l).setSize(123, 20).setFont(createFont("arial", 14))
      .setLineHeight(14)
        .setColor(color(128))
          .setColorBackground(color(255, 100))
            .setColorForeground(color(255, 100))


              ;
  }


}
public void bang() {
}
void draw() {
delay(15);
  background(myColor);
  myColor = lerpColor(c1, c2, n);
  n += (1-n)* 0.1; 
  funkcija();
   }
void funkcija(){ 
   int suma= 0;
    for( i=1;i<=11;i++){
    int brojmi=0;
    textValueZVANJE = cp5.get(Textfield.class, "ZVANJE").getText();
    textValueBODOVI = cp5.get(Textfield.class, "BODOVI").getText();
    int bodovi = int(textValueBODOVI);
    int zvanje = int(textValueZVANJE);

    int mii, vii;
    if(bodovi>0){
    if (mi) {  
      println("mi"+brojmi+i); 
      int ukupno = 162 + zvanje;      
      vii = ukupno - bodovi;
      cp5.get(Textarea.class, "MIVI"+i).setText(textValueBODOVI+"         "+vii);
       mi=false;
       vi=false;
      cp5.get(Textfield.class, "BODOVI").clear();
      cp5.get(Textfield.class, "ZVANJE").clear();
      loop();

    }
    if (vi) { 
      println("vi"+i);
      int ukupno = 162 + zvanje;
      mii = ukupno - bodovi;
      cp5.get(Textarea.class, "MIVI"+i).setText(mii+"         "+textValueBODOVI);
       mi=false;
       vi=false;
      cp5.get(Textfield.class, "BODOVI").clear();
      cp5.get(Textfield.class, "ZVANJE").clear();
        }
}
       brojmi++; }
}


public void controlEvent(ControlEvent theEvent) {
  mi = theEvent.getController().getName().equals("MI");
  vi = theEvent.getController().getName().equals("VI");
}
public void clear() {
  cp5.get(Textfield.class, "BODOVI").clear();
  cp5.get(Textfield.class, "ZVANJE").clear();
}
4

1 に答える 1

0

Mmmmm, I don't know if I got your question. If your question is: "i need draw() function to wait for input or something like that.", then use a flag (boolean value) to decide if draw or not. When user input something, assign true to that value.

So your code should be:

void draw () {
    // put the code you want to run anyways here...
    // code 
    // code
    if (hasUserInput) {
        // here write the code you should wait to execute
    }
}
于 2012-09-12T22:34:22.497 に答える