Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Assignment6;
- import com.sun.tools.javac.comp.Check;
- import javafx.geometry.Insets;
- import javafx.scene.control.Label;
- import javafx.scene.control.CheckBox;
- import javafx.scene.control.TextArea;
- import javafx.scene.layout.*;
- import javafx.event.ActionEvent; //**Need to import
- import javafx.event.EventHandler; //**Need to import
- import java.util.ArrayList;
- import java.util.List;
- import javafx.collections.ObservableList;
- import javafx.scene.Node;
- //import all other necessary javafx classes here
- //----
- public class SelectPane extends BorderPane
- {
- //instance variables i needed
- private ArrayList<Club> clubList;
- private TilePane pane;
- private Label info,total;
- private int totalMembers;
- private List<CompareMethod> boxs = new ArrayList<>();
- private ArrayList<String> active = new ArrayList<>();
- //constructor
- public SelectPane(ArrayList<Club> list)
- {
- //initialize instance variables
- this.clubList = list;
- totalMembers = 0;
- this.info = new Label("Select Some Clubs");
- this.total = new Label("Total number of members is: " + totalMembers);
- this.pane = new TilePane();
- this.setTop(info);
- this.setLeft(pane);
- this.setBottom(total);
- } //end of constructor
- //This method uses the newly added parameter 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)
- {
- clubList.add(newClub);
- CheckBox box = new CheckBox(newClub.toString());
- SelectionHandler handle = new SelectionHandler();
- box.setOnAction(handle);
- boxs.add(new CompareMethod(box,newClub));
- box.setId(newClub.getClubName());
- pane.setPrefColumns(boxs.size());
- this.pane.getChildren().add(box);
- this.setLeft(pane);
- }
- //create a SelectionHandler class
- private class SelectionHandler implements EventHandler<ActionEvent>
- {
- //Override the abstact method handle()
- public void handle(ActionEvent event)
- {
- ObservableList<Node> list = pane.getChildren();
- for (int i = 0; i < list.size(); i++)
- {
- CheckBox box = (CheckBox)list.get(i);
- CompareMethod each = null;
- for (CompareMethod method : boxs) {
- if (method.getBox().getId().equalsIgnoreCase(box.getId())) {
- each = method;
- }
- }
- if (each == null)
- {
- continue;
- }
- if (each.getBox().getId().equalsIgnoreCase(box.getId()))
- {
- if (each.getBox().isSelected())
- {
- if (!(active.contains(each.getBox().getId())))
- {
- totalMembers += each.getClub().getNumberOfMembers();
- active.add(each.getBox().getId());
- } else {
- continue;
- }
- } else {
- if (active.contains(each.getBox().getId()))
- {
- totalMembers -= each.getClub().getNumberOfMembers();
- active.remove(each.getBox().getId());
- }
- }
- }
- }
- total.setText("Total number of members is: " + totalMembers);
- }
- } //end of SelectHandler class
- //class to allow me to compare club to the checkbox to get amount of members
- private class CompareMethod
- {
- private CheckBox box;
- private Club club;
- public CompareMethod(CheckBox box, Club club)
- {
- this.box = box;
- this.club = club;
- }
- public CheckBox getBox()
- {
- return box;
- }
- public Club getClub()
- {
- return club;
- }
- }
- } //end of SelectPane class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement