Class HomePanel

All Implemented Interfaces:
ActionListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible

public class HomePanel extends JPanel implements ActionListener
The HomePanel class represents the main menu panel for the Snake Game. It allows the user to select between:
  • Easy Mode
  • Hard Mode
  • Exit the game

The panel uses a CardLayout for future extensibility, making it easy to switch between different panels (e.g., game panel, settings panel).

See Also:
  • Field Details

    • cardLayout

      private CardLayout cardLayout
      The layout manager that handles panel switching.
    • easyMode

      private JButton easyMode
      Button for starting the game in Easy mode.
    • hardMode

      private JButton hardMode
      Button for starting the game in Hard mode.
    • exitGame

      private JButton exitGame
      Button for exiting the game.
  • Constructor Details

    • HomePanel

      public HomePanel()
      Constructs the HomePanel and initializes the layout and components.

      Uses CardLayout for future expansion, allowing the addition of more panels.

  • Method Details

    • setupMainMenu

      private void setupMainMenu()
      Sets up the main menu with buttons and a title.

      It uses GridBagLayout to arrange the components vertically.

    • createButton

      private JButton createButton(String text)
      Creates a styled button with hover effects.

      The button has the following properties:

      • Font: Arial, BOLD, 20
      • Foreground color: WHITE
      • Background color: Green (darkens on hover)
      • Padding and border adjustments
      Parameters:
      text - The label text for the button.
      Returns:
      The styled JButton with hover effects.
    • actionPerformed

      public void actionPerformed(ActionEvent e)
      Handles button click actions.

      Currently not used, but required for ActionListener implementation.

      Specified by:
      actionPerformed in interface ActionListener
      Parameters:
      e - The action event triggered by button click.