This site requires JavaScript, please enable it in your browser!
Greenfoot back
Sly_D
Sly_D wrote ...

2013/4/16

World swapping

Sly_D Sly_D

2013/4/16

#
Hey guys I wonder if anyone could help, I have a crosshair as my mouse follwer in my world which works fine, I want to click on one of my buttons to change to a different world. Can anyone help me with what code to use and where to add this code so that I may swap to a different world that i have created? Thanks really appreciate it :)
Sly_D Sly_D

2013/4/16

#
And if anyone has any ways on using JLabels in my program that would also be very useful thanks
danpost danpost

2013/4/16

#
As far as JLabels, the Java tutorials has a page on How to Use Labels. As far as the button, a simple button class should have a constructor that recieves a String (used for its caption; it should also be saved in an instance field, to be used when the button is clicked). Add a static String field to the class to be set to the text of any button that is clicked and add a static method to output the value of that field to outside classes (the world class). This method should save the value of the static field to a local variable within the method, then clear the static field to an empty string, and finally return the local value. The world 'act' method or a method it calls should get the value of the static field by calling that method and save it in a local field and then compare its value with all possible values and act on any matches. The act method in the button class should detect mouseclicks on the button and set the static field to its text when clicked on.
Sly_D Sly_D

2013/4/22

#
Thanks man really helped appreciate it :)
You need to login to post a reply.