-1

我试图不绘制另一个按钮顶部。

  • 我画了第一个按钮。一切安好
  • 我尝试在第一个按钮的顶部绘制第二个按钮。它不让我。一切安好。
  • 我尝试在第二个按钮的顶部绘制第三个按钮。它不让我。一切安好。

问题是它只记得我画的最后一个按钮。当我在绘制第三个按钮后尝试在第一个按钮上绘制时;它让我做到了。

我能做什么,它会记住所有的按钮。

按钮类:

class Node {

  int node_x;  // x Position
  int node_y;  // y Position
  int node_w;   // width
  int node_h;   // height
  String node_name;  // name of the node
  boolean mouseOverButton; // if mouse is over button


    Node(int temp_node_x, int temp_node_y, int temp_node_number) {

    node_x = temp_node_x;
    node_y = temp_node_y;
    node_w = 100;
    node_h = 36;
    node_name = Integer.toString(temp_node_number);  //integer to string
    mouseOverButton = false;
  }

  void display() {
    rectMode(CENTER);
    if (mouseOverButton) {
      fill (YELLOW);
    }else {
      fill(MID_GRAY);
    }

    rect(node_x, node_y, node_w, node_h);    //button
    fill(BLACK);    //text color black
    text(node_name, node_x, node_y+6); //button text
    rectMode(CORNER); // reset
  }



  boolean overButton() {

    if (mouseX >= node_x -50  && mouseX <= node_x + 50 && mouseY >= node_y -18 && mouseY <= node_y + 18) {
      mouseOverButton = true;
      //Returns true back to main program
      return mouseOverButton;
    }
    else {
      mouseOverButton = false;
      //Returns false back to main program
      return mouseOverButton;
    }
  } 

鼠标按下

  if (mouseY >= 25 && current_tab == "Node") {
    if ( ((mouseX > 50) && (mouseY > 50)) && ((mouseX < 490) && (mouseY < 340))  ) {     // Do not create the node edge of the window

      for (int i = 0; i < listofNodes.size();i++) {         // Loop through the ArrayList.            
        Node currentNode = (Node) listofNodes.get(i);       // To be able to access the methods for the ArrayList element at the position 'i'
        if (currentNode.overButton()) { 
          onit = true;
        }
        else {
          onit = false;
        }
      }
      if (!onit) {
        listofNodes.add(new Node(mouseX, mouseY, nodecounter++));  // create a new button
      }
    } 

}
4

1 回答 1

0

我所要做的就是在 onit 为真时添加一个休息

于 2012-05-30T15:10:04.337 回答