How to drag and drop on processing
in
Programming Questions
•
1 year ago
I could not figure out what kind of strategy i should follow to drag and drop the buttons i have created.
On Node pane i create the buttons and on Move pane i have to drag and drop the buttons i have created.
This is what i have got so far.
/*
Node pane
*/
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
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
}
void display(){
rectMode(CENTER);
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
}
}
and this is how i call the class
}else if (current_tab == "Node"){ // If the current tab is Node tab then do
//for (int i = listofNodes.size()-1; i >= 0; i--) {
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'
currentNode.display(); // Call the display() method for the object pointed at by currentNode
} // End of for loop
}else if (current_tab == "Move"){ // If the current tab is Move tab then do something
//
and mousePressed is
void mousePressed() {
/*
Used for node class
Create new buttons
*/
if (mouseY >= 25 && current_tab == "Node") {
listofNodes.add(new Node(mouseX, mouseY, nodecounter++)); //
}
}
1