Skip to content
This repository was archived by the owner on Jan 6, 2026. It is now read-only.
Garkatron edited this page Sep 20, 2024 · 2 revisions

The Router class is responsible for managing navigation between different pages in an application. It provides methods for route registration, page navigation, and rendering the current page.

Description

The class allows developers to define routes that are associated with specific pages and control navigation between them. It also handles the rendering and updating of the current page based on user interactions.

Features

  • Route Registration: Allows associating paths with specific pages using the registerRoute() method.
  • Navigation: Facilitates navigation through routes with the navigateTo() method and allows returning to the previous page with backPreviousPage().
  • Index Control: Offers methods to move forward and backward through registered routes using next() and back().
  • Page Rendering: Renders the current page using the renderCurrentPage() method.
  • Page Update: Updates the current page based on mouse coordinates through updatePage(int mx, int my).

Main Methods

Route Registration Variants

  • registerRoute(String path, Page page): Registers a route with a specific page using a string path.

  • registerRoute(int i, String path, Page page): Registers a route with an index and a string path, allowing for structured routes based on index.

  • registerRoute(int i, Page page): Registers a route with just an index, using the index as the key.

Navigation Methods

  • navigateTo(String path): Navigates to the specified route.
  • backPreviousPage(): Returns to the previous page, if available.
  • back(): Navigates to the previous route based on the index.
  • next(): Navigates to the next route based on the index.

Rendering and Updating

  • renderCurrentPage(): Renders the current page.
  • updatePage(int mx, int my): Updates the current page with mouse coordinates.
  • getCurrentPage(): Returns the current page.

Example Usage

Router router = new Router();
Page homePage = new HomePage();
Page settingsPage = new SettingsPage();

router.registerRoute("/home", homePage);
router.registerRoute("/settings", settingsPage);
router.registerRoute(1, "/profile", new ProfilePage());
router.registerRoute(2, settingsPage);

// Navigate to the home page
router.navigateTo("/home");

// Render the current page
router.renderCurrentPage();

Clone this wiki locally