Class CreateJar

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class CreateJar extends Api
CreateJar class is a JPanel that allows the user to create a new jar. It contains a title field, a goal field, and two buttons: create and cancel.
  • The title field is required, while the goal field is optional.
  • The title field must not be empty or only contain "For".
  • The goal field must be a positive number or empty.
If the user clicks the create button, it will call the Api.createJar(java.lang.String, java.lang.Double) method to create a new jar. If the user clicks the cancel button, it will revert the fields to their initial values and switch the card back to the Jars panel.
See Also:
  • Field Details

    • gbLayout

      GridBagLayout gbLayout
      GridBagLayout object used for layout management.
    • gbc

      GridBagConstraints object used for layout management.
    • title

      JLabel title
      Label that serves as the title of the panel.
    • titleLabel

      JLabel titleLabel
      Label for the titleField field.
    • goalLabel

      JLabel goalLabel
      Label for the goalField field.
    • titleField

      JTextField titleField
      Field to enter the title of the jar.
    • goalField

      JTextField goalField
      Field to enter the goal amount for the jar.
    • createJarBtn

      JButton createJarBtn
      Button to create a new jar.
    • cancelBtn

      JButton cancelBtn
      Button to revert the fields to their initial values and switch the card back to the Jars panel.
  • Constructor Details

    • CreateJar

      CreateJar()
      Constructs a new CreateJar panel.
  • Method Details

    • createJarHandler

      private void createJarHandler(ActionEvent event)
      Handles the action of creating a jar. It validates the input fields and calls the Api.createJar(java.lang.String, java.lang.Double) method. If the input is valid, it updates the user information and switches the card back to the Jars panel. If the input is invalid, it shows an error message.
      Parameters:
      event - The event that triggered the action
    • cancelHandler

      private void cancelHandler(ActionEvent event)
      Handles the action of canceling the jar creation. It reverts the input fields to their initial values and switches the card back to the Jars panel.
      Parameters:
      event - The event that triggered the action