ButtonGroup - Final Version
Button Group - Radio Group Logic
Observations:
1. Our ButtonGroup is not very extensible since we have hard-coded the Button creation logic within
the ButtonGroup class, we'd prefer flexibility in the number of buttons in our menu.
2. When looking at our code, we observe that we're performing the identical operations on each
button, this repetition of similar code suggests that using an Array and a loop could simplify
our code and could provide more flexibility.Arrays as Constructor Input Parameters
//Create Class ButtonGroup
class ButtonGroup{
//instance variables
Button[] buttons; //declare an array of Buttons
int numButtons; //how many Buttons are there?
int activeBtnIndex; //currently selected Button (FSM memory)
ButtonGroup( Button buttons){ //constructor method
this.buttons =buttons; //initialize instance variables with
numButtons=buttons.length;
activeBtnIndex=0; //set default
}
//methods
}Initialize Button Array in Main Tab
ButtonGroup clicked(int mx, int my)
Last updated