Coders Packet

Rock Paper Scissor game using java

By Bibhab Das

This is a simple rock, paper and scissors game made with Java and GUI is also added here for a better experience.

The provided code represents a Rock, Paper, Scissors game implemented using Java Swing. Here's an overview of the project:

1. Project Title: Rock, Paper, Scissors Game
- The project is a simple implementation of the popular game "Rock, Paper, Scissors" using Java Swing for the graphical user interface.

2. Packages:
- `javax.swing: This package provides classes and interfaces for creating GUI components and managing GUI applications.
- `java.awt: This package contains classes for creating and managing GUI components and providing basic functionality for GUI applications.
- `java.awt.event`: This package includes classes and interfaces for handling events in GUI applications.

3. Classes and Components:
- `RockPaperScissorsGame` (class): It represents the main class of the project that extends `JFrame` and implements `ActionListener`. It creates the game window, buttons, and result label, and handles button clicks and game logic.
- `JFrame` (class): It is a top-level container class provided by Swing. It represents the main window of a GUI application.
- `JButton` (class): It is a component that represents a button that can trigger an action when clicked.
- `JLabel` (class): It is a component used to display a short text or an image.
- `ActionEvent` (class): It represents an event that occurs when a button or component is triggered.
- `ActionListener` (interface): It defines the contract for classes that listen to and handle action events.

4. Functionality:
- The game window is created using `JFrame` and contains buttons for rock, paper, and scissors.
- The 'ActionListener' interface is implemented to handle button clicks.
- The 'playGame()' method is called when a button is clicked, which determines the player's choice, generates the computer's choice, and determines the game result.
- The game result is displayed in a `JLabel` component.
- The background color of the result label changes based on the game outcome.

5. Execution:
- The 'main()' method is used to start the application by creating an instance of `RockPaperScissorsGame` inside the `SwingUtilities.invokeLater()` method.
- This ensures that the Swing components are created and updated on the Event Dispatch Thread (EDT), which is the dedicated thread for handling GUI events.

if you won against the computer then it will be green.

if you lose the game it will be red.

if you both choose the same option then it will be white.

Overall, the project provides a simple and interactive Rock, Paper, Scissors game where the user can choose their move and see the result displayed on the screen.

 

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Bibhab Das (bibhab123)

Download packets of source code on Coders Packet