Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Feb 25th, 2020 179 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Assignment #: Arizona State University CSE205 #6
  2. //Name: Summer Beckman
  3. //StudentID: 1216922252
  4. //Lecture: MW 4:35
  5. //Description: CreatePane generates a pane where a user can enter
  6. //a club information and create a list of available clubs.
  7.  
  8. //import all other necessary javafx classes here
  9. //----
  10. import java.util.ArrayList;
  11. import javafx.scene.layout.HBox;
  12. import javafx.scene.paint.Color;
  13. import javafx.event.ActionEvent;    //**Need to import
  14. import javafx.event.EventHandler;   //**Need to import
  15. import javafx.geometry.Insets;
  16. import javafx.geometry.Pos;
  17. import javafx.scene.layout.*;
  18. import javafx.scene.control.*;
  19. import javafx.scene.control.Button;
  20.  
  21. public class CreatePane extends HBox
  22. {
  23.     ArrayList<Club> clubList;
  24.  
  25.     //The relationship between CreatePane and SelectPane is Aggregation
  26.     private SelectPane SelectPane;
  27.     private TextArea textSpace;
  28.     private Button create;
  29.     private TextField text1, text2, text3;
  30.     private Label titleLabel, memberLabel, uniLabel, infoText;
  31.    
  32.     //constructor
  33.     public CreatePane(ArrayList<Club> list, SelectPane sePane)
  34.     {
  35.         this.clubList = list;
  36.         this.SelectPane = sePane;
  37.  
  38.         //initialize each instance variable (textfields, labels, textarea, button, etc.)
  39.         //and set up the layout
  40.         //----
  41.         this.titleLabel = new Label("Title");
  42.         this.memberLabel = new Label("Number of Members");
  43.         this.uniLabel = new Label("University");
  44.         this.create = new Button("Create a club");
  45.         this.infoText = new Label("/n");
  46.         this.textSpace = new TextArea();
  47.         this.text1 = new TextField("");
  48.         this.text2 = new TextField("");
  49.         this.text3 = new TextField("");
  50.         this.getChildren().addAll(titleLabel, memberLabel,uniLabel, create, textSpace, text1, text2, text3);
  51.        
  52.         //create a GridPane hold those labels & text fields.
  53.         //you can choose to use .setPadding() or setHgap(), setVgap()
  54.         //to control the spacing and gap, etc.
  55.         //----
  56.         GridPane centerPane = new GridPane();
  57.         centerPane.setHgap(10);
  58.         centerPane.setVgap(10);
  59.         centerPane.setPadding(new Insets(10, 10, 10, 10));
  60.         centerPane.setAlignment(Pos.CENTER);
  61.        
  62.         //You might need to create a sub pane to hold the button
  63.         //----
  64.         GridPane.setConstraints(uniLabel, 0, 2);
  65.         GridPane.setConstraints(text3, 1, 2);
  66.  
  67.         GridPane.setConstraints(memberLabel, 0, 1);
  68.         GridPane.setConstraints(text2, 1, 2);
  69.        
  70.         GridPane.setConstraints(titleLabel, 0, 0);
  71.         GridPane.setConstraints(text1, 1, 2);
  72.        
  73.         GridPane.setConstraints(create, 1, 3);
  74.        
  75.         centerPane.getChildren().addAll(uniLabel, text3, memberLabel, text2, titleLabel, text1);
  76.         //register/link source object with event handler
  77.         //----
  78.         textSpace.setVisible(true);
  79.         textSpace.resizeRelocate(0, 40, 500, 400);
  80.         for (Club each : clubList)
  81.         {
  82.             textSpace.appendText(textSpace.getText() + each.toString());
  83.         }
  84.     } //end of constructor
  85.  
  86. //Create a ButtonHandler class
  87. //ButtonHandler listens to see if the button "Create" is pushed or not,
  88. //When the event occurs, it get a club's Title, its number of members, and its university
  89. //information from the relevant text fields, then create a new club and add it inside
  90. //the clubList. Meanwhile it will display the club's information inside the text area.
  91. //using the toString method of the Club class.
  92. //It also does error checking in case any of the textfields are empty,
  93. //or a non-numeric value was entered for its number of members
  94. private class ButtonHandler implements EventHandler<ActionEvent>
  95. {
  96.     //Override the abstact method handle()
  97.     public void handle(ActionEvent event)
  98.     {
  99.         //declare any necessary local variables here
  100.         //---
  101.         int numMembers;
  102.         String title = text1.getText();
  103.         String members = text3.getText();
  104.         String university = text2.getText();
  105.  
  106.         //when a text field is empty and the button is pushed
  107.         //handle the case here
  108.         if (title.equalsIgnoreCase("") || university.equalsIgnoreCase("") || members.equalsIgnoreCase(""))
  109.         {
  110.             infoText.setTextFill(Color.RED);
  111.             infoText.setText("Please fill all fields.");
  112.             return;
  113.            
  114.         } else {
  115.          //when a non-numeric value was entered for its number of members
  116.          //and the button is pushed
  117.          //you will need to use try & catch block to catch
  118.          //the NumberFormatException
  119.          //----
  120.             try {
  121.                 numMembers = Integer.parseInt(members);
  122.             }
  123.             catch
  124.                 (NumberFormatException e){
  125.                     infoText.setTextFill(Color.RED);
  126.                     infoText.setText("Please enter a integer for a number of members.");
  127.                     return;
  128.                 }
  129.          
  130.          //When a club of an existing club name in the list
  131.          //was attempted to be added, do not add it to the list
  132.          //and display a message "Club not added - duplicate"
  133.          
  134.          for (Club each : clubList)
  135.          {
  136.              if (each.getClubName().equalsIgnoreCase(title));
  137.              {
  138.                  infoText.setTextFill(Color.RED);
  139.                  infoText.setText("Club not added - duplicate");
  140.                  return;
  141.              }
  142.          }
  143.          
  144.          //at the end, don't forget to update the new arrayList
  145.          //information on the SelectPanel
  146.          //----
  147.          infoText.setText("");
  148.          Club club = new Club(titleLabel.getText(), numMembers, uniLabel.getText());        
  149.          SelectPane.updateClubList(club);
  150.          textSpace.appendText(club.toString());
  151.             }
  152.  
  153.         } //end of handle() method
  154.     } //end of ButtonHandler class
  155. }
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