From c0469b853e55e7f41b8bc480191ff24126d90133 Mon Sep 17 00:00:00 2001
From: andrewme <andrewme@stud.ntnu.no>
Date: Wed, 13 Mar 2024 22:53:17 +0100
Subject: [PATCH] Added javadoc and finished the application

---
 .idea/sonarlint/issuestore/index.pb           |  6 +-
 .idea/sonarlint/securityhotspotstore/index.pb |  6 +-
 .../java/edu/ntnu/stud/cardgame/CardGame.java | 74 +++++++++++++------
 .../cardgame/controller/ButtonController.java | 70 ++++++++++++++----
 .../stud/cardgame/controller/DeckOfCards.java | 32 ++++++--
 .../cardgame/controller/ImageImporter.java    | 67 +++++++++++++----
 .../edu/ntnu/stud/cardgame/model/Hand.java    | 48 ++++++++----
 .../ntnu/stud/cardgame/model/PlayingCard.java |  5 +-
 .../cardgame/util/ImageLoadingException.java  | 30 ++++++++
 .../ntnu/stud/cardgame/view/HomeFrame.java    | 44 +++++++++--
 .../stud/cardgame/view/components/Button.java | 17 -----
 .../cardgame/view/components/Buttons.java     | 44 +++++++++--
 .../cardgame/view/components/CardFrame.java   | 46 ++++++++----
 .../view/components/ChecksForHand.java        | 43 ++++++++++-
 .../view/components/CustomButton.java         | 35 +++++++++
 .../cardgame/view/components/OverlayView.java | 23 +++++-
 16 files changed, 457 insertions(+), 133 deletions(-)
 create mode 100644 src/main/java/edu/ntnu/stud/cardgame/util/ImageLoadingException.java
 delete mode 100644 src/main/java/edu/ntnu/stud/cardgame/view/components/Button.java
 create mode 100644 src/main/java/edu/ntnu/stud/cardgame/view/components/CustomButton.java

diff --git a/.idea/sonarlint/issuestore/index.pb b/.idea/sonarlint/issuestore/index.pb
index d623585..d9fa6a1 100644
--- a/.idea/sonarlint/issuestore/index.pb
+++ b/.idea/sonarlint/issuestore/index.pb
@@ -55,4 +55,8 @@ Gsrc/main/java/edu/ntnu/stud/cardgame/view/components/ChecksForHand.java,3\e\3e
 u
 Esrc/main/java/edu/ntnu/stud/cardgame/controller/ButtonController.java,8\f\8ff99be84aa52505518939fa5cd13c156bd35d9f
 u
-Esrc/main/java/edu/ntnu/stud/cardgame/view/components/OverlayView.java,3\5\35c4072017451a22960f8a35d958c1895f70199c
\ No newline at end of file
+Esrc/main/java/edu/ntnu/stud/cardgame/view/components/OverlayView.java,3\5\35c4072017451a22960f8a35d958c1895f70199c
+t
+Dsrc/main/java/edu/ntnu/stud/cardgame/util/ImageLoadingException.java,0\9\0975c71ba9476317994e6c45939476748599abe3
+v
+Fsrc/main/java/edu/ntnu/stud/cardgame/view/components/CustomButton.java,f\e\fece8beb53ba8d32175b4846d92b1535902e95aa
\ No newline at end of file
diff --git a/.idea/sonarlint/securityhotspotstore/index.pb b/.idea/sonarlint/securityhotspotstore/index.pb
index d623585..d9fa6a1 100644
--- a/.idea/sonarlint/securityhotspotstore/index.pb
+++ b/.idea/sonarlint/securityhotspotstore/index.pb
@@ -55,4 +55,8 @@ Gsrc/main/java/edu/ntnu/stud/cardgame/view/components/ChecksForHand.java,3\e\3e
 u
 Esrc/main/java/edu/ntnu/stud/cardgame/controller/ButtonController.java,8\f\8ff99be84aa52505518939fa5cd13c156bd35d9f
 u
-Esrc/main/java/edu/ntnu/stud/cardgame/view/components/OverlayView.java,3\5\35c4072017451a22960f8a35d958c1895f70199c
\ No newline at end of file
+Esrc/main/java/edu/ntnu/stud/cardgame/view/components/OverlayView.java,3\5\35c4072017451a22960f8a35d958c1895f70199c
+t
+Dsrc/main/java/edu/ntnu/stud/cardgame/util/ImageLoadingException.java,0\9\0975c71ba9476317994e6c45939476748599abe3
+v
+Fsrc/main/java/edu/ntnu/stud/cardgame/view/components/CustomButton.java,f\e\fece8beb53ba8d32175b4846d92b1535902e95aa
\ No newline at end of file
diff --git a/src/main/java/edu/ntnu/stud/cardgame/CardGame.java b/src/main/java/edu/ntnu/stud/cardgame/CardGame.java
index f4ee2e7..b83efb7 100644
--- a/src/main/java/edu/ntnu/stud/cardgame/CardGame.java
+++ b/src/main/java/edu/ntnu/stud/cardgame/CardGame.java
@@ -7,30 +7,56 @@ import javafx.scene.Scene;
 import javafx.scene.image.Image;
 import javafx.stage.Stage;
 
+/**
+ * The main class for the Card Game application. This class sets up the primary stage and the
+ * home frame, and sets up the button actions for the home frame.
+ * This is where the application runs from.
+ *
+ * @author André Merkesdal
+ * @version 1.0
+ */
 public class CardGame extends Application {
-    public static void main(String[] args) {
-        launch(args);
-    }
 
-    @Override
-    public void start(Stage primaryStage) {
-
-        primaryStage.setTitle("Card Game");
-        primaryStage.getIcons().add(new Image(
-            "file:src/main/resources/edu/ntnu/stud/cardgame/CardGameLogo.png"));
-
-        HomeFrame homeFrame = new HomeFrame();
-        ButtonController btnController = new ButtonController(homeFrame);
-
-        setupButtonActions(homeFrame, btnController);
-
-        primaryStage.setScene(new Scene(homeFrame, 1000, 800));
-        primaryStage.show();
-    }
-
-    private void setupButtonActions(HomeFrame homeFrame, ButtonController btnController) {
-        homeFrame.getButtons().actionOnDealButton(e -> btnController.actionOnDealButton());
-        homeFrame.getButtons().actionOnCheckButton(e -> btnController.actionOnCheckButton());
-        homeFrame.getButtons().actionOnQuitButton(e -> btnController.actionOnQuitButton());
-    }
+  /**
+   * The main method for the Card Game application. This method launches the application.
+   *
+   * @param args The command line arguments.
+   */
+  public static void main(String[] args) {
+    launch(args);
+  }
+
+  /**
+   * The start method for the Card Game application. This method sets up the primary stage and the
+   * home frame, and sets up the button actions for the home frame.
+   *
+   * @param primaryStage The primary stage for the application.
+   */
+  @Override
+  public void start(Stage primaryStage) {
+
+    primaryStage.setTitle("Card Game");
+    primaryStage.getIcons().add(new Image(
+        "file:src/main/resources/edu/ntnu/stud/cardgame/CardGameLogo.png"));
+
+    HomeFrame homeFrame = new HomeFrame();
+    ButtonController btnController = new ButtonController(homeFrame);
+
+    setupButtonActions(homeFrame, btnController);
+
+    primaryStage.setScene(new Scene(homeFrame, 1000, 800));
+    primaryStage.show();
+  }
+
+  /**
+   * Sets up the button actions for the home frame.
+   *
+   * @param homeFrame     The home frame for the application.
+   * @param btnController The button controller for the application.
+   */
+  private void setupButtonActions(HomeFrame homeFrame, ButtonController btnController) {
+    homeFrame.getButtons().actionOnDealButton(e -> btnController.actionOnDealButton());
+    homeFrame.getButtons().actionOnCheckButton(e -> btnController.actionOnCheckButton());
+    homeFrame.getButtons().actionOnQuitButton(e -> btnController.actionOnQuitButton());
+  }
 }
diff --git a/src/main/java/edu/ntnu/stud/cardgame/controller/ButtonController.java b/src/main/java/edu/ntnu/stud/cardgame/controller/ButtonController.java
index 794464a..ec5f16e 100644
--- a/src/main/java/edu/ntnu/stud/cardgame/controller/ButtonController.java
+++ b/src/main/java/edu/ntnu/stud/cardgame/controller/ButtonController.java
@@ -3,24 +3,44 @@ package edu.ntnu.stud.cardgame.controller;
 import edu.ntnu.stud.cardgame.model.Hand;
 import edu.ntnu.stud.cardgame.model.PlayingCard;
 import edu.ntnu.stud.cardgame.view.HomeFrame;
-import edu.ntnu.stud.cardgame.view.components.Button;
+import edu.ntnu.stud.cardgame.view.components.CustomButton;
 import edu.ntnu.stud.cardgame.view.components.OverlayView;
-import javafx.application.Platform;
 import java.util.stream.Collectors;
+import javafx.application.Platform;
 
+/**
+ * Controller class for the buttons in the HomeFrame and their actions.
+ * The class is responsible for creating a new deck of cards, dealing cards, and checking the hand
+ * when the buttons are pressed.
+ *
+ * @author André Merkesdal
+ * @version 1.0
+ */
 public class ButtonController {
 
+  // Class fields
   private final DeckOfCards deck;
   private Hand hand;
-  private HomeFrame homeFrame;
-  private ImageImporter imageImporter;
+  private final HomeFrame homeFrame;
 
+  /**
+   * Constructor for the ButtonController class.
+   * Initializes the class fields and creates a new deck of cards.
+   *
+   * @param homeFrame The HomeFrame object used in the application.
+   */
   public ButtonController(HomeFrame homeFrame) {
-    this.imageImporter = new ImageImporter();
+    ImageImporter imageImporter = new ImageImporter("/edu/ntnu/stud/cardgame/images/");
     this.deck = new DeckOfCards(imageImporter);
     this.homeFrame = homeFrame;
   }
 
+  /**
+   * Method for dealing cards from the deck and updating the
+   * corresponding frames.
+   *
+   * @param n The number of cards to deal.
+   */
   private void dealCards(int n) {
     this.hand = new Hand(deck.dealHand(n));
     homeFrame.getCheckedHand().clear();
@@ -28,17 +48,15 @@ public class ButtonController {
     homeFrame.getCardFrame().addCards(hand);
   }
 
-  public void actionOnDealButton() {
-    OverlayView overlayView = new OverlayView();
-    overlayView.addButtons(createDealButton(5, overlayView), createDealButton(10, overlayView), createDealButton(15, overlayView));
-
-    overlayView.getOverlay().setOnMouseClicked(e -> homeFrame.getChildren().remove(overlayView.getOverlay()));
-
-    homeFrame.getChildren().add(overlayView.getOverlay());
-  }
-
-  private Button createDealButton(int n, OverlayView overlayView) {
-    Button button = new Button("Deal " + n);
+  /**
+   * Private method for creating a deal button with a given number of cards to deal.
+   *
+   * @param n The number of cards to deal.
+   * @param overlayView The overlay view to add the button to.
+   * @return The created button.
+   */
+  private CustomButton createDealButton(int n, OverlayView overlayView) {
+    CustomButton button = new CustomButton("Deal " + n);
     button.setOnAction(e -> {
       dealCards(n);
       homeFrame.getChildren().remove(overlayView.getOverlay());
@@ -46,6 +64,23 @@ public class ButtonController {
     return button;
   }
 
+  /**
+   * Decides the action to be taken when the deal button is pressed.
+   */
+  public void actionOnDealButton() {
+    OverlayView overlayView = new OverlayView();
+    overlayView.addButtons(createDealButton(5, overlayView),
+        createDealButton(10, overlayView), createDealButton(15, overlayView));
+
+    overlayView.getOverlay().setOnMouseClicked(e ->
+        homeFrame.getChildren().remove(overlayView.getOverlay()));
+
+    homeFrame.getChildren().add(overlayView.getOverlay());
+  }
+
+  /**
+   * Decides the action to be taken when the check button is pressed.
+   */
   public void actionOnCheckButton() {
     homeFrame.getCheckedHand().clear();
     homeFrame.getCheckedHand().setSumField(Integer.toString(hand.sumOfFaces()));
@@ -62,6 +97,9 @@ public class ButtonController {
     homeFrame.getCheckedHand().setFlushField(flush);
   }
 
+  /**
+   * Decides the action to be taken when the quit button is pressed.
+   */
   public void actionOnQuitButton() {
     Platform.exit();
   }
diff --git a/src/main/java/edu/ntnu/stud/cardgame/controller/DeckOfCards.java b/src/main/java/edu/ntnu/stud/cardgame/controller/DeckOfCards.java
index b7cc067..5a43f07 100644
--- a/src/main/java/edu/ntnu/stud/cardgame/controller/DeckOfCards.java
+++ b/src/main/java/edu/ntnu/stud/cardgame/controller/DeckOfCards.java
@@ -1,19 +1,29 @@
 package edu.ntnu.stud.cardgame.controller;
 
-import edu.ntnu.stud.cardgame.model.Hand;
 import edu.ntnu.stud.cardgame.model.PlayingCard;
-
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Random;
-import java.util.stream.Collectors;
 
+/**
+ * A deck of playing cards. The deck is initialized with 52 cards, and cards can be dealt from the
+ * deck.
+ *
+ * @author André Merkesdal
+ * @version 1.0
+ */
 public class DeckOfCards {
-  private static final char[] SUITS = {'H', 'D', 'S', 'C'};
 
-  private PlayingCard[] cards;
-  private Random random;
+  // Class fields
+  private final PlayingCard[] cards;
+  private final Random random;
+  private static final char[] SUITS = {'H', 'D', 'S', 'C'};
 
+  /**
+   * Constructs a new deck of cards. Takes an image importer as an argument to import images for the
+   * cards used in the game to create the cards with their images.
+   *
+   * @param imageImporter an image importer to import images for the cards used in the game.
+   */
   public DeckOfCards(ImageImporter imageImporter) {
     this.cards = new PlayingCard[52];
     this.random = new Random();
@@ -26,6 +36,14 @@ public class DeckOfCards {
     }
   }
 
+  /**
+   * Deals a hand of n cards from the deck. The cards are chosen randomly from the deck, and the
+   * cards are removed from the deck.
+   *
+   * @param n the number of cards to deal.
+   * @return a collection of n cards.
+   * @throws IllegalArgumentException if n is less than 0 or greater than 52.
+   */
   public Collection<PlayingCard> dealHand(int n) {
     if (n < 0 || n > 52) {
       throw new IllegalArgumentException("Invalid number of cards: " + n);
diff --git a/src/main/java/edu/ntnu/stud/cardgame/controller/ImageImporter.java b/src/main/java/edu/ntnu/stud/cardgame/controller/ImageImporter.java
index 86a61cd..b7579e9 100644
--- a/src/main/java/edu/ntnu/stud/cardgame/controller/ImageImporter.java
+++ b/src/main/java/edu/ntnu/stud/cardgame/controller/ImageImporter.java
@@ -1,45 +1,82 @@
 package edu.ntnu.stud.cardgame.controller;
 
-import edu.ntnu.stud.cardgame.model.PlayingCard;
-import javafx.scene.image.Image;
-
+import edu.ntnu.stud.cardgame.util.ImageLoadingException;
 import java.io.InputStream;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javafx.scene.image.Image;
 
+/**
+ * Class for importing images from the file system and storing them in a map for easy access.
+ * The class is used to import images of playing cards for the card game application.
+ *
+ * @author André Merkesdal
+ * @version 1.0
+ */
 public class ImageImporter {
+
+  // Class fields
+  private static final char[] SUITS = {'H', 'D', 'S', 'C'};
+  private final String path;
   Map<String, Image> images;
 
-  public ImageImporter() {
+  /**
+   * Constructor for the ImageImporter class.
+   * Initializes the class fields and imports the images from the file system.
+   *
+   * @param path The path to the directory containing the images.
+   */
+  public ImageImporter(String path) {
+    this.path = path;
     this.images = new HashMap<>();
     this.initialize();
   }
 
+  /**
+   * Method for importing images from the file system and storing them in a map.
+   */
   public void initialize() {
-    String path = "/edu/ntnu/stud/cardgame/images/";
     List<String> files = new ArrayList<>();
 
-    char[] suits = {'H', 'D', 'S', 'C'};
-    for (int i = 0; i < 4; i++) {
+    for (char suit : SUITS) {
       for (int j = 1; j <= 13; j++) {
-        files.add(path + suits[i] + j + ".png");
+        files.add(path + suit + j + ".png");
       }
     }
 
     for (String file : files) {
-      InputStream stream = getClass().getResourceAsStream(file);
-      if (stream == null) {
-        throw new RuntimeException("Failed to load image file: " + file);
+      try (InputStream stream = getClass().getResourceAsStream(file)) {
+        if (stream == null) {
+          throw new ImageLoadingException("Failed to load image file: " + file);
+        }
+        Image image = new Image(stream);
+        images.put(getFilenameWithoutExtension(file), image);
+      } catch (Exception e) {
+        throw new ImageLoadingException("Failed to load image file: " + file, e);
       }
-      Image image = new Image(stream);
-      images.put(getFilenameWithoutExtension(file), image);
     }
   }
 
+  /**
+   * Private method for extracting the filename from a path without the file extension.
+   * Used to create keys for the image map.
+   *
+   * @param path The path to the file.
+   * @return The filename without the file extension.
+   */
   private String getFilenameWithoutExtension(String path) {
     String file = path.substring(path.lastIndexOf("/") + 1);
     return file.substring(0, file.lastIndexOf("."));
   }
 
+  /**
+   * Method for retrieving an image from the map using a key.
+   *
+   * @param key The key for the image in the map.
+   * @return The image corresponding to the key.
+   */
   public Image getImage(String key) {
     Image image = images.get(key);
     if (image == null) {
@@ -47,4 +84,4 @@ public class ImageImporter {
     }
     return image;
   }
-}
+}
\ No newline at end of file
diff --git a/src/main/java/edu/ntnu/stud/cardgame/model/Hand.java b/src/main/java/edu/ntnu/stud/cardgame/model/Hand.java
index 774b5df..b070f3c 100644
--- a/src/main/java/edu/ntnu/stud/cardgame/model/Hand.java
+++ b/src/main/java/edu/ntnu/stud/cardgame/model/Hand.java
@@ -3,25 +3,33 @@ package edu.ntnu.stud.cardgame.model;
 import java.util.ArrayList;
 import java.util.Collection;
 
-public class Hand {
-  private Collection<PlayingCard> cards;
-
-  public Hand(Collection<PlayingCard> cards) {
-    this.cards = cards;
-  }
-
-  public Collection<PlayingCard> getCards() {
-    return cards;
-  }
+/**
+ * Class representing a hand of playing cards.
+ * The class is used to represent a hand of playing cards and contains methods for checking the
+ * hand for specific combinations. This class is a Record class because it is a simple data
+ * container with no behavior.
+ *
+ * @author André Merkesdal
+ * @version 1.0
+ */
+public record Hand(Collection<PlayingCard> cards) {
 
+  /**
+   * Method for calculating the sum of the faces of the cards in the hand.
+   *
+   * @return The sum of the faces of the cards in the hand.
+   */
   public int sumOfFaces() {
-    int sum = 0;
-    for (PlayingCard card : cards) {
-      sum += card.getFace();
-    }
-    return sum;
+    return cards.stream()
+        .mapToInt(PlayingCard::getFace)
+        .sum();
   }
 
+  /**
+   * Method for getting all the cards of hearts in the hand.
+   *
+   * @return A collection of all the cards of hearts in the hand.
+   */
   public Collection<PlayingCard> getCardsOfHearts() {
     Collection<PlayingCard> hearts = new ArrayList<>();
     for (PlayingCard card : cards) {
@@ -32,6 +40,11 @@ public class Hand {
     return hearts;
   }
 
+  /**
+   * Method for checking if the hand contains the queen of spades.
+   *
+   * @return True if the hand contains the queen of spades, false otherwise.
+   */
   public boolean hasQueenOfSpades() {
     for (PlayingCard card : cards) {
       if (card.getSuit() == 'S' && card.getFace() == 12) {
@@ -41,6 +54,11 @@ public class Hand {
     return false;
   }
 
+  /**
+   * Method for checking if the hand contains a flush.
+   *
+   * @return True if the hand contains a flush, false otherwise.
+   */
   public boolean isFlush() {
     char suit = cards.iterator().next().getSuit();
     for (PlayingCard card : cards) {
diff --git a/src/main/java/edu/ntnu/stud/cardgame/model/PlayingCard.java b/src/main/java/edu/ntnu/stud/cardgame/model/PlayingCard.java
index 1f28de7..595142e 100644
--- a/src/main/java/edu/ntnu/stud/cardgame/model/PlayingCard.java
+++ b/src/main/java/edu/ntnu/stud/cardgame/model/PlayingCard.java
@@ -9,13 +9,13 @@ import javafx.scene.image.ImageView;
  * The card can also be one of 4 suits: Spade, Heart, Diamonds and Clubs.
  *
  * @author ntnu
- * @version 2021-03-13
+ * @version 1.0
  */
 public class PlayingCard {
 
+  // Class fields
   private final char suit; // 'S'=spade, 'H'=heart, 'D'=diamonds, 'C'=clubs
   private final int face; // a number between 1 and 13
-
   private final ImageView imageView;
 
   /**
@@ -29,6 +29,7 @@ public class PlayingCard {
    * @param suit The suit of the card, as a single character. 'S' for Spades,
    *             'H' for Heart, 'D' for Diamonds and 'C' for clubs
    * @param face The face value of the card, an integer between 1 and 13
+   * @param image The image of the card, as an Image object
    * @throws IllegalArgumentException if suit or face have invalid values.
    */
   public PlayingCard(char suit, int face, Image image) {
diff --git a/src/main/java/edu/ntnu/stud/cardgame/util/ImageLoadingException.java b/src/main/java/edu/ntnu/stud/cardgame/util/ImageLoadingException.java
new file mode 100644
index 0000000..b7296e2
--- /dev/null
+++ b/src/main/java/edu/ntnu/stud/cardgame/util/ImageLoadingException.java
@@ -0,0 +1,30 @@
+package edu.ntnu.stud.cardgame.util;
+
+/**
+ * Custom exception class for handling image loading exceptions.
+ * The class is used to handle exceptions when importing images from the file system.
+ *
+ * @author André Merkesdal
+ * @version 1.0
+ */
+public class ImageLoadingException extends RuntimeException {
+
+  /**
+   * Constructor for the ImageLoadingException class.
+   *
+   * @param message The message to be displayed when the exception is thrown.
+   */
+  public ImageLoadingException(String message) {
+    super(message);
+  }
+
+  /**
+   * Constructor for the ImageLoadingException class.
+   *
+   * @param message The message to be displayed when the exception is thrown.
+   * @param cause The cause of the exception.
+   */
+  public ImageLoadingException(String message, Throwable cause) {
+    super(message, cause);
+  }
+}
\ No newline at end of file
diff --git a/src/main/java/edu/ntnu/stud/cardgame/view/HomeFrame.java b/src/main/java/edu/ntnu/stud/cardgame/view/HomeFrame.java
index 73413c9..50ad21e 100644
--- a/src/main/java/edu/ntnu/stud/cardgame/view/HomeFrame.java
+++ b/src/main/java/edu/ntnu/stud/cardgame/view/HomeFrame.java
@@ -3,17 +3,30 @@ package edu.ntnu.stud.cardgame.view;
 import edu.ntnu.stud.cardgame.view.components.Buttons;
 import edu.ntnu.stud.cardgame.view.components.CardFrame;
 import edu.ntnu.stud.cardgame.view.components.ChecksForHand;
+import java.util.Objects;
 import javafx.geometry.Pos;
 import javafx.scene.layout.GridPane;
 import javafx.scene.layout.StackPane;
 
-import java.util.Objects;
-
+/**
+ * The main frame of the game. Contains the card frame, buttons and checks for hand.
+ * This is the main frame of the game where all the other
+ * components are added.
+ *
+ * @author André Merkesdal
+ * @version 1.0
+ */
 public class HomeFrame extends StackPane {
-  private CardFrame cardFrame;
-  private Buttons buttons;
-  private ChecksForHand checkedHand;
 
+  // The card frame, buttons and additional info for the hand.
+  private final CardFrame cardFrame;
+  private final Buttons buttons;
+  private final ChecksForHand checkedHand;
+
+  /**
+   * Creates a new HomeFrame. Sets the size and adds the card frame, buttons and checks for hand.
+   * Also adds the global stylesheet.
+   */
   public HomeFrame() {
 
     this.setPrefSize(1000, 800);
@@ -29,6 +42,11 @@ public class HomeFrame extends StackPane {
     this.getChildren().add(getContent());
   }
 
+  /**
+   * Creates the content of the frame. Adds the card frame, buttons and checks for hand.
+   *
+   * @return The content of the frame.
+   */
   private GridPane getContent() {
 
     GridPane content = new GridPane();
@@ -43,16 +61,30 @@ public class HomeFrame extends StackPane {
     return content;
   }
 
+  /**
+   * Get the buttons.
+   *
+   * @return The buttons.
+   */
   public Buttons getButtons() {
     return buttons;
   }
 
+  /**
+   * Get the checked hand.
+   *
+   * @return The checked hand.
+   */
   public ChecksForHand getCheckedHand() {
     return checkedHand;
   }
 
+  /**
+   * Get the card frame.
+   *
+   * @return The card frame.
+   */
   public CardFrame getCardFrame() {
     return cardFrame;
   }
-
 }
diff --git a/src/main/java/edu/ntnu/stud/cardgame/view/components/Button.java b/src/main/java/edu/ntnu/stud/cardgame/view/components/Button.java
deleted file mode 100644
index 27e7629..0000000
--- a/src/main/java/edu/ntnu/stud/cardgame/view/components/Button.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package edu.ntnu.stud.cardgame.view.components;
-
-public class Button extends javafx.scene.control.Button {
-  private final String name;
-
-  public Button(String name) {
-    this.name = name;
-    this.setText(name);
-    this.getStyleClass().add("button");
-
-    this.setMinSize(160, 60);
-  }
-
-  public String getName() {
-    return name;
-  }
-}
diff --git a/src/main/java/edu/ntnu/stud/cardgame/view/components/Buttons.java b/src/main/java/edu/ntnu/stud/cardgame/view/components/Buttons.java
index e75d52d..72f3adc 100644
--- a/src/main/java/edu/ntnu/stud/cardgame/view/components/Buttons.java
+++ b/src/main/java/edu/ntnu/stud/cardgame/view/components/Buttons.java
@@ -5,16 +5,31 @@ import javafx.event.EventHandler;
 import javafx.geometry.Insets;
 import javafx.scene.layout.VBox;
 
+/**
+ * A class for the buttons in the game used to deal, check and quit the game.
+ * The class extends VBox and contains three buttons.
+ *
+ * @author André Merkesdal
+ * @version 1.0
+ */
 public class Buttons extends VBox {
-  private final Button deal;
-  private final Button check;
-  private final Button quit;
+
+  // The buttons used in the game.
+  private final CustomButton deal;
+  private final CustomButton check;
+  private final CustomButton quit;
+
+  /**
+   * Constructor for the Buttons class.
+   * Sets the padding for the VBox and adds the buttons to the VBox.
+   * Also sets the margins for the buttons.
+   */
   public Buttons() {
     this.setPadding(new Insets(15));
 
-    this.deal = new Button("Deal Hand");
-    this.check = new Button("Check Hand");
-    this.quit = new Button("Quit Game");
+    this.deal = new CustomButton("Deal Hand");
+    this.check = new CustomButton("Check Hand");
+    this.quit = new CustomButton("Quit Game");
 
     this.getChildren().addAll(deal, check, quit);
 
@@ -22,17 +37,30 @@ public class Buttons extends VBox {
     VBox.setMargin(quit, new Insets(240, 0, 0, 0));
   }
 
+  /**
+   * Method for setting the action on the deal button.
+   *
+   * @param event The event to be set on the deal button.
+   */
   public void actionOnDealButton(EventHandler<ActionEvent> event) {
     deal.setOnAction(event);
   }
 
+  /**
+   * Method for setting the action on the check button.
+   *
+   * @param event The event to be set on the check button.
+   */
   public void actionOnCheckButton(EventHandler<ActionEvent> event) {
     check.setOnAction(event);
   }
 
+  /**
+   * Method for setting the action on the quit button.
+   *
+   * @param event The event to be set on the quit button.
+   */
   public void actionOnQuitButton(EventHandler<ActionEvent> event) {
     quit.setOnAction(event);
   }
-
-
 }
diff --git a/src/main/java/edu/ntnu/stud/cardgame/view/components/CardFrame.java b/src/main/java/edu/ntnu/stud/cardgame/view/components/CardFrame.java
index d5b5039..3b74175 100644
--- a/src/main/java/edu/ntnu/stud/cardgame/view/components/CardFrame.java
+++ b/src/main/java/edu/ntnu/stud/cardgame/view/components/CardFrame.java
@@ -6,25 +6,39 @@ import javafx.geometry.Pos;
 import javafx.scene.layout.TilePane;
 
 /**
- * A frame for displaying cards.
+ * A frame for displaying cards. This class is a subclass of TilePane.
+ * It is used to display a hand of cards in a graphical user interface.
  *
- * @version 2021-03-29
+ * @author André Merkesdal
+ * @version 1.0
  */
 public class CardFrame extends TilePane {
-    public CardFrame() {
-        this.setMinSize(700, 500);
-        this.setMaxSize(700, 500);
-        this.getStyleClass().add("card-frame");
-        this.setAlignment(Pos.CENTER);
-    }
 
-    public void addCards(Hand hand) {
-        hand.getCards().stream()
-            .map(PlayingCard::getImage)
-            .forEach(this.getChildren()::add);
-    }
+  /**
+   * Constructs a new CardFrame object.
+   */
+  public CardFrame() {
+    this.setMinSize(700, 500);
+    this.setMaxSize(700, 500);
+    this.getStyleClass().add("card-frame");
+    this.setAlignment(Pos.CENTER);
+  }
 
-    public void clear() {
-        this.getChildren().clear();
-    }
+  /**
+   * Adds the cards from a hand to the CardFrame.
+   *
+   * @param hand The hand to add cards from.
+   */
+  public void addCards(Hand hand) {
+    hand.cards().stream()
+        .map(PlayingCard::getImage)
+        .forEach(this.getChildren()::add);
+  }
+
+  /**
+   * Removes all cards from the CardFrame and clears it.
+   */
+  public void clear() {
+    this.getChildren().clear();
+  }
 }
diff --git a/src/main/java/edu/ntnu/stud/cardgame/view/components/ChecksForHand.java b/src/main/java/edu/ntnu/stud/cardgame/view/components/ChecksForHand.java
index 7ea112e..531a8a1 100644
--- a/src/main/java/edu/ntnu/stud/cardgame/view/components/ChecksForHand.java
+++ b/src/main/java/edu/ntnu/stud/cardgame/view/components/ChecksForHand.java
@@ -4,12 +4,24 @@ import javafx.scene.control.TextField;
 import javafx.scene.layout.GridPane;
 import javafx.scene.text.Text;
 
+/**
+ * A class to get additional information about a hand.
+ *
+ * @author André Merkesdal
+ * @version 1.0
+ */
 public class ChecksForHand extends GridPane {
-  private TextField sumField;
-  private TextField heartsField;
-  private TextField queenOfSpadesField;
-  private TextField flushField;
 
+  // Class fields
+  private final TextField sumField;
+  private final TextField heartsField;
+  private final TextField queenOfSpadesField;
+  private final TextField flushField;
+
+  /**
+   * Constructor for the ChecksForHand class. Sets up the grid pane and adds the
+   * necessary fields.
+   */
   public ChecksForHand() {
     this.setHgap(20);
     this.setVgap(10);
@@ -41,22 +53,45 @@ public class ChecksForHand extends GridPane {
     this.add(flushField, 1, 3);
   }
 
+  /**
+   * Method to set the sum field with the sum of the faces of the hand.
+   *
+   * @param sum The sum to set.
+   */
   public void setSumField(String sum) {
     sumField.setText(sum);
   }
 
+  /**
+   * Method to set the hearts field with the number of cards of Hearts in the hand.
+   *
+   * @param hearts The number of cards of Hearts to set.
+   */
   public void setHeartsField(String hearts) {
     heartsField.setText(hearts);
   }
 
+  /**
+   * Method to set the Queen of Spades field if the hand includes the Queen of Spades.
+   *
+   * @param queenOfSpades Yes if the hand includes the Queen of Spades, otherwise No.
+   */
   public void setQueenOfSpadesField(String queenOfSpades) {
     queenOfSpadesField.setText(queenOfSpades);
   }
 
+  /**
+   * Method to set the flush field if the hand is a flush.
+   *
+   * @param flush Yes if the hand is a flush, otherwise No.
+   */
   public void setFlushField(String flush) {
     flushField.setText(flush);
   }
 
+  /**
+   * Method to clear all the fields.
+   */
   public void clear() {
     sumField.clear();
     heartsField.clear();
diff --git a/src/main/java/edu/ntnu/stud/cardgame/view/components/CustomButton.java b/src/main/java/edu/ntnu/stud/cardgame/view/components/CustomButton.java
new file mode 100644
index 0000000..4835584
--- /dev/null
+++ b/src/main/java/edu/ntnu/stud/cardgame/view/components/CustomButton.java
@@ -0,0 +1,35 @@
+package edu.ntnu.stud.cardgame.view.components;
+
+/**
+ * A custom button with a name and styling for the game.
+ *
+ * @author André Merkesdal
+ * @version 1.0
+ */
+public class CustomButton extends javafx.scene.control.Button {
+
+  // The name of the button
+  private final String name;
+
+  /**
+   * Creates a new custom button with the given name.
+   *
+   * @param name The name of the button
+   */
+  public CustomButton(String name) {
+    this.name = name;
+    this.setText(name);
+    this.getStyleClass().add("button");
+
+    this.setMinSize(160, 60);
+  }
+
+  /**
+   * Returns the name of the button.
+   *
+   * @return The name of the button
+   */
+  public String getName() {
+    return name;
+  }
+}
diff --git a/src/main/java/edu/ntnu/stud/cardgame/view/components/OverlayView.java b/src/main/java/edu/ntnu/stud/cardgame/view/components/OverlayView.java
index 21ce10b..d2f53de 100644
--- a/src/main/java/edu/ntnu/stud/cardgame/view/components/OverlayView.java
+++ b/src/main/java/edu/ntnu/stud/cardgame/view/components/OverlayView.java
@@ -5,14 +5,30 @@ import javafx.scene.control.Button;
 import javafx.scene.layout.StackPane;
 import javafx.scene.layout.VBox;
 
+/**
+ * A view for an overlay with buttons.
+ *
+ * @author André Merkesdal
+ * @version 1.0
+ */
 public class OverlayView {
-  private StackPane overlay;
 
+  // The overlay
+  private final StackPane overlay;
+
+  /**
+   * Creates a new overlay view.
+   */
   public OverlayView() {
     this.overlay = new StackPane();
     this.overlay.setStyle("-fx-background-color: rgba(0,0,0,0.49);");
   }
 
+  /**
+   * Adds buttons to the overlay.
+   *
+   * @param buttons The buttons to add.
+   */
   public void addButtons(Button... buttons) {
     VBox buttonBox = new VBox();
     buttonBox.getStyleClass().add("content");
@@ -23,6 +39,11 @@ public class OverlayView {
     this.overlay.getChildren().add(buttonBox);
   }
 
+  /**
+   * Get the overlay.
+   *
+   * @return The overlay.
+   */
   public StackPane getOverlay() {
     return this.overlay;
   }
-- 
GitLab