https://github.com/afa-farkhod/lottery-game
Lottery Game which is based on two digit number guessing
https://github.com/afa-farkhod/lottery-game
eclipse-ide java swing-gui windowbuilder
Last synced: 2 months ago
JSON representation
Lottery Game which is based on two digit number guessing
- Host: GitHub
- URL: https://github.com/afa-farkhod/lottery-game
- Owner: afa-farkhod
- License: gpl-3.0
- Created: 2023-03-07T00:32:51.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-07-02T01:29:18.000Z (almost 2 years ago)
- Last Synced: 2025-02-02T01:13:33.546Z (4 months ago)
- Topics: eclipse-ide, java, swing-gui, windowbuilder
- Language: Java
- Homepage:
- Size: 30.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Lottery-Game
Lottery Game which is based on two digit number guessing
![]()
## [Implementation](https://github.com/af4092/Lottery-Game/tree/main/Lottery/src/org/eclipse/wb/swt)
- `SWTResourceManager.java` represents a simple lottery game implemented using the Java Swing and SWT libraries. The program displays a graphical user interface (GUI) window that allows the user to play the lottery game.
- The code starts with import statements that bring in necessary classes from the `javax.swing` and `org.eclipse.swt` packages.
- The class `Lottery` is defined and extends the `Shell` class from SWT. It represents the main window of the application.
- The class contains several instance variables, such as "shlLottery" (the main shell), "Rules" (a label to display rules), `tfInput` (a text field to input the user's guess), `btnPlay` (a button to play the lottery), and `lbDisplay` (a label to display the lottery result).
- The "main" method is the entry point of the application. It creates an instance of the "Lottery" class and opens the main window.
- The `generateLotteryNumber` method generates a random two-digit lottery number.
- The `checkMatch` method takes two arguments: the user's guess and the generated lottery number. It checks whether the guess matches the lottery number and returns the corresponding prize amount based on the matching criteria.
- The "open" method sets up the GUI components, opens the main window, and starts the event loop to handle user interactions.
- The `createContents` method creates and initializes the GUI components, sets their positions and sizes, and registers event listeners.
- The event listener for the `btnPlay` button reads the user's guess from the `tfInput` text field, converts it to an integer, generates a lottery number, checks for a match, and updates the `lbDisplay` label with the lottery number and the result message.
- `Lottery.java` represents a utility class called `SWTResourceManager` that provides various methods for managing OS resources associated with SWT controls, such as colors, fonts, and images.
- The code includes: Import statements for necessary SWT and Java IO classes.
- A class-level comment describing the purpose of the class and its licensing information.
- The class "SWTResourceManager" contains static methods for managing colors, images, and fonts used in SWT-based applications.
- The class includes methods for obtaining system colors, creating custom colors, loading images from files, and creating decorated images.
- The class uses various maps to cache and reuse created resources, such as colors, images, and decorated images.
- The class also provides methods to dispose of the cached resources when they are no longer needed.
- The `disposeColors`, `disposeImages`, and `disposeFonts` methods are used to release the operating system resources associated with the cached colors, images, and fonts, respectively.