Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javafx.scene.control.Label;
- import javafx.scene.control.CheckBox;
- import javafx.scene.layout.*;
- import javafx.event.ActionEvent; //**Need to import
- import javafx.event.EventHandler; //**Need to import
- import java.util.ArrayList;
- import javafx.collections.ObservableList;
- import javafx.scene.Node;
- //import all other necessary javafx classes here
- //----
- public class SelectPane extends BorderPane
- {
- private ArrayList<Club> clubList;
- private ArrayList<CheckBox> checkBoxes;
- private Label numMembers;
- private int amountOfMembers;
- private Pane pane;
- private VBox leftbox;
- //constructor
- public SelectPane(ArrayList<Club> list)
- {
- //initialize instance variables
- this.clubList = list;
- amountOfMembers = 0;
- Label selectClubs = new Label("Select some club");
- numMembers = new Label("The total number of members for the selected club(s): " + amountOfMembers);
- pane = new Pane();
- leftbox = new VBox();
- checkBoxes = new ArrayList<>(checkBoxes);
- //set up the layout
- //----
- selectClubs.setLayoutX(1);
- selectClubs.setLayoutY(2);
- leftbox.setLayoutX(1);
- leftbox.setLayoutY(10);
- numMembers.setLayoutX(1);
- numMembers.setLayoutY(340);
- //create an empty pane wh
- //here you can add check boxes later
- //----
- pane.getChildren().addAll(selectClubs,numMembers,leftbox);
- //sample.SelectPane is a BorderPane - add the components here
- //----
- this.setCenter(pane);
- } //end of constructor
- //This method uses the newly added parameter sample.Club object
- //to create a CheckBox and add it to a pane created in the constructor
- //Such check box needs to be linked to its handler class
- public void updateClubList(Club newClub)
- {
- //-------
- CheckBox temp = new CheckBox(newClub.toString());
- leftbox.getChildren().add(temp);
- temp.setOnAction(new SelectionHandler());
- checkBoxes.add(temp);
- }
- //create a SelectionHandler class
- private class SelectionHandler implements EventHandler<ActionEvent>
- {
- //Override the abstact method handle()
- public void handle(ActionEvent event)
- {
- int count = 0;
- for(int i = 0; i < checkBoxes.size(); i++) {
- if(checkBoxes.get(i).isSelected()) {
- count++;
- amountOfMembers = amountOfMembers + clubList.get(i).getNumberOfMembers();
- }
- if (count == 0) {
- amountOfMembers = 0;
- }
- }
- numMembers.setText("The total number of members for the selected clubs(s): " + numMembers);
- count = 0;
- amountOfMembers = 0;
- //When any radio button is selected or unselected
- //the total number of members of selected clubs should be updated
- //and displayed using a label.
- }
- } //end of SelectHandler class
- } //end of sample.SelectPane class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement