TOC PREV NEXT INDEX



Light changing methods


We will now create the methods to control the state of the traffic light.

  1. Choose "Goto method code" from the Code menu in the Canvas Composer.
  2. Type the following code into the method section:
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
repaint();
}
public void cycle() {
state++;
if (state > GREEN) state = RED;
repaint();
}
  1. Close the Canvas Composer by choosing 'Exit' from the file menu in the Composer. When you are asked if you wish to save your changes, answer "yes". If you are running the tryout version of Simplicity for Java, you may use FinishedTrafficLight.java for the rest of this Tutorial.
  2. In the Simplicity IDE, click on the 'Java Source Files' Group in the Project Tree to see the file that was just created, TrafficLight.java.
  3. Control-click TrafficLight.java in the IDE.
  4. Choose 'Compile' from the pop-up menu which will appear.
  5. Choose 'Java Class Files' or 'All Files' in the Project Tree to see the new class file that you've created.

Data Representations, Inc.
http://www.datarepresentations.com
support@datarepresentations.com
sales@datarepresentations.com
TOC PREV NEXT INDEX