SHARE
TWEET

SelectPane

a guest Feb 26th, 2020 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import javafx.scene.control.Label;
  3. import javafx.scene.control.CheckBox;
  4. import javafx.scene.layout.*;
  5. import javafx.event.ActionEvent;    //**Need to import
  6. import javafx.event.EventHandler;   //**Need to import
  7. import java.util.ArrayList;
  8. import javafx.collections.ObservableList;
  9. import javafx.scene.Node;
  10.  
  11. //import all other necessary javafx classes here
  12. //----
  13.  
  14. public class SelectPane extends BorderPane
  15. {
  16.     private ArrayList<Club> clubList;
  17.     private ArrayList<CheckBox> checkBoxes;
  18.     private Label numMembers;
  19.     private int amountOfMembers;
  20.     private Pane pane;
  21.     private VBox leftbox;
  22.  
  23.     //constructor
  24.     public SelectPane(ArrayList<Club> list)
  25.     {
  26.         //initialize instance variables
  27.         this.clubList = list;
  28.         amountOfMembers = 0;
  29.         Label selectClubs = new Label("Select some club");
  30.         numMembers = new Label("The total number of members for the selected club(s): " + amountOfMembers);
  31.         pane = new Pane();
  32.         leftbox = new VBox();
  33.         checkBoxes = new ArrayList<>(checkBoxes);
  34.  
  35.         //set up the layout
  36.         //----
  37.  
  38.         selectClubs.setLayoutX(1);
  39.         selectClubs.setLayoutY(2);
  40.         leftbox.setLayoutX(1);
  41.         leftbox.setLayoutY(10);
  42.         numMembers.setLayoutX(1);
  43.         numMembers.setLayoutY(340);
  44.  
  45.  
  46.  
  47.  
  48.         //create an empty pane wh
  49.         //here you can add check boxes later
  50.         //----
  51.  
  52.         pane.getChildren().addAll(selectClubs,numMembers,leftbox);
  53.  
  54.  
  55.         //sample.SelectPane is a BorderPane - add the components here
  56.         //----
  57.  
  58.         this.setCenter(pane);
  59.  
  60.  
  61.     } //end of constructor
  62.  
  63.     //This method uses the newly added parameter sample.Club object
  64.     //to create a CheckBox and add it to a pane created in the constructor
  65.     //Such check box needs to be linked to its handler class
  66.     public void updateClubList(Club newClub)
  67.     {
  68.         //-------
  69.         CheckBox temp = new CheckBox(newClub.toString());
  70.  
  71.             leftbox.getChildren().add(temp);
  72.             temp.setOnAction(new SelectionHandler());
  73.             checkBoxes.add(temp);
  74.  
  75.     }
  76.  
  77.     //create a SelectionHandler class
  78.     private class SelectionHandler implements EventHandler<ActionEvent>
  79.     {
  80.         //Override the abstact method handle()
  81.         public void handle(ActionEvent event)
  82.         {
  83.  
  84.  
  85.             int count = 0;
  86.  
  87.             for(int i = 0; i < checkBoxes.size(); i++) {
  88.  
  89.                 if(checkBoxes.get(i).isSelected()) {
  90.  
  91.                     count++;
  92.                     amountOfMembers = amountOfMembers + clubList.get(i).getNumberOfMembers();
  93.                 }
  94.  
  95.                 if (count == 0) {
  96.                     amountOfMembers = 0;
  97.                 }
  98.  
  99.             }
  100.  
  101. numMembers.setText("The total number of members for the selected clubs(s): " + numMembers);
  102.  
  103.             count = 0;
  104.             amountOfMembers = 0;
  105.  
  106.  
  107.             //When any radio button is selected or unselected
  108.             //the total number of members of selected clubs should be updated
  109.             //and displayed using a label.
  110.  
  111.  
  112.         }
  113.     } //end of SelectHandler class
  114. } //end of sample.SelectPane class
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top