Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Java
You last visited: Today at 13:13

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



request rock paper scissors games java GUI

Discussion on request rock paper scissors games java GUI within the Java forum part of the Coders Den category.

Reply
 
Old   #1
 
macboyem07's Avatar
 
elite*gold: 0
Join Date: Dec 2012
Posts: 239
Received Thanks: 33
Unhappy request rock paper scissors games java GUI

anyone have a simple GUI JAVA codes or tutorial of rock paper scissors games ..give me please

thanks in advance
macboyem07 is offline  
Old 03/01/2016, 18:28   #2
 
KingDingD0ng's Avatar
 
elite*gold: 11
The Black Market: 103/0/0
Join Date: Jun 2011
Posts: 1,847
Received Thanks: 141
Theres a WYSIWYG-Editor in Netbeans. You can try it out. Produces Swing Code
KingDingD0ng is offline  
Old 04/15/2016, 16:06   #3
 
samkeezz's Avatar
 
elite*gold: 0
Join Date: Apr 2016
Posts: 18
Received Thanks: 13
Hello,

Well i have one, i had to develop that game in the school 1 year ago. If you want you can add me on skype i can upload the project on MEGA or something. I used the IDE Netbeans so it wouldn't be bad to use that too to bypass problems.

LG samkeez
samkeezz is offline  
Old 04/16/2016, 14:23   #4
 
0xFADED's Avatar
 
elite*gold: 7
Join Date: Dec 2013
Posts: 446
Received Thanks: 187
I was bored, so I made one for you
Have fun

Code:
package moe.lukas.rps;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.util.concurrent.ThreadLocalRandom;

import static java.awt.BorderLayout.CENTER;
import static java.awt.BorderLayout.EAST;
import static java.awt.BorderLayout.WEST;

public class Main extends JFrame {
    /**
     * The actions a player may use
     */
    private String[] actions = {"Rock", "Paper", "Scissors"};

    /**
     * The button locations
     */
    private String[] locations = {WEST, CENTER, EAST};

    /**
     * The listener for all 3 buttons
     */
    private ActionListener buttonListener = e -> {
        // Generate a random action
        int random = ThreadLocalRandom.current().nextInt(0, 3);
        String comAction = actions[random];

        // Rate the current situation
        String rating = rate(e.getActionCommand(), comAction);

        // Show a result alert
        JOptionPane.showMessageDialog(null, rating);
    };

    /**
     * Private constructor invoked by SwingUtils.invokeLater()
     * Creates the GUI and shows it
     */
    private Main() {
        setTitle("Rock, Paper, Scissors");
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setPreferredSize(new Dimension(300, 150));

        // Create a container that holds the buttons
        JPanel container = new JPanel();

        // Set the layout
        container.setLayout(new BorderLayout());

        // Create the buttons
        for (int i = 0; i < actions.length; i++) {
            JButton temp = new JButton(actions[i]);
            temp.addActionListener(buttonListener);
            container.add(temp, locations[i]);
        }

        // Finish
        add(container);
        pack();

        // Display the frame
        setVisible(true);
    }

    /**
     * Runs the private constructor
     *
     * [MENTION=1985011]param[/MENTION] args
     */
    public static void main(String[] args) {
        SwingUtilities.invokeLater(Main::new);
    }

    /**
     * Rates the current situation and returns a result string.
     * Probably way too complicated, but hey:
     *  You get the idea what it does, right?
     *
     * [MENTION=1985011]param[/MENTION] userAction
     * [MENTION=1985011]param[/MENTION] comAction
     * [MENTION=326673]return[/MENTION]
     */
    private String rate(String userAction, String comAction) {
        String msg = "";

        switch (userAction) {
            case "Rock":
                switch (comAction) {
                    case "Rock":
                        msg = "Draw. Both chose Rock!";
                        break;

                    case "Paper":
                        msg = "You lost. Paper wraps stone!";
                        break;

                    case "Scissors":
                        msg = "You won. Rock breaks scissors!";
                        break;
                }
                break;

            case "Paper":
                switch (comAction) {
                    case "Rock":
                        msg = "You won. Paper wraps stone!";
                        break;

                    case "Paper":
                        msg = "Draw. Both chose paper!";
                        break;

                    case "Scissors":
                        msg = "You lost. Scissors cuts paper!";
                        break;
                }
                break;

            case "Scissors":
                switch (comAction) {
                    case "Rock":
                        msg = "You lost. Rock breaks scissors!";
                        break;

                    case "Paper":
                        msg = "You won. Scissors cuts paper!";
                        break;

                    case "Scissors":
                        msg = "Draw. Both chose scissors!";
                        break;
                }
                break;
        }

        return msg;
    }
}
0xFADED is offline  
Old 04/16/2016, 21:16   #5
 
Dantox's Avatar
 
elite*gold: 0
Join Date: Jan 2012
Posts: 228
Received Thanks: 45
Quote:
Originally Posted by 0xFADED View Post
I was bored, so I made one for you
Have fun

Code:
package moe.lukas.rps;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.util.concurrent.ThreadLocalRandom;

import static java.awt.BorderLayout.CENTER;
import static java.awt.BorderLayout.EAST;
import static java.awt.BorderLayout.WEST;

public class Main extends JFrame {
    /**
     * The actions a player may use
     */
    private String[] actions = {"Rock", "Paper", "Scissors"};

    /**
     * The button locations
     */
    private String[] locations = {WEST, CENTER, EAST};

    /**
     * The listener for all 3 buttons
     */
    private ActionListener buttonListener = e -> {
        // Generate a random action
        int random = ThreadLocalRandom.current().nextInt(0, 3);
        String comAction = actions[random];

        // Rate the current situation
        String rating = rate(e.getActionCommand(), comAction);

        // Show a result alert
        JOptionPane.showMessageDialog(null, rating);
    };

    /**
     * Private constructor invoked by SwingUtils.invokeLater()
     * Creates the GUI and shows it
     */
    private Main() {
        setTitle("Rock, Paper, Scissors");
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setPreferredSize(new Dimension(300, 150));

        // Create a container that holds the buttons
        JPanel container = new JPanel();

        // Set the layout
        container.setLayout(new BorderLayout());

        // Create the buttons
        for (int i = 0; i < actions.length; i++) {
            JButton temp = new JButton(actions[i]);
            temp.addActionListener(buttonListener);
            container.add(temp, locations[i]);
        }

        // Finish
        add(container);
        pack();

        // Display the frame
        setVisible(true);
    }

    /**
     * Runs the private constructor
     *
     * [MENTION=1985011]param[/MENTION] args
     */
    public static void main(String[] args) {
        SwingUtilities.invokeLater(Main::new);
    }

    /**
     * Rates the current situation and returns a result string.
     * Probably way too complicated, but hey:
     *  You get the idea what it does, right?
     *
     * [MENTION=1985011]param[/MENTION] userAction
     * [MENTION=1985011]param[/MENTION] comAction
     * [MENTION=326673]return[/MENTION]
     */
    private String rate(String userAction, String comAction) {
        String msg = "";

        switch (userAction) {
            case "Rock":
                switch (comAction) {
                    case "Rock":
                        msg = "Draw. Both chose Rock!";
                        break;

                    case "Paper":
                        msg = "You lost. Paper wraps stone!";
                        break;

                    case "Scissors":
                        msg = "You won. Rock breaks scissors!";
                        break;
                }
                break;

            case "Paper":
                switch (comAction) {
                    case "Rock":
                        msg = "You won. Paper wraps stone!";
                        break;

                    case "Paper":
                        msg = "Draw. Both chose paper!";
                        break;

                    case "Scissors":
                        msg = "You lost. Scissors cuts paper!";
                        break;
                }
                break;

            case "Scissors":
                switch (comAction) {
                    case "Rock":
                        msg = "You lost. Rock breaks scissors!";
                        break;

                    case "Paper":
                        msg = "You won. Scissors cuts paper!";
                        break;

                    case "Scissors":
                        msg = "Draw. Both chose scissors!";
                        break;
                }
                break;
        }

        return msg;
    }
}
Enums wären schöner.
Dantox is offline  
Reply


Similar Threads Similar Threads
Is there a hack on the rock, paper, scissors ?
12/05/2014 - 4Story - 1 Replies
Sorry for my bad english ,i Used the translator. Anything, if a bad business Please message
Rock-paper-scissors game in 4story?
08/21/2012 - 4Story - 1 Replies
is there any trick for Rock-paper-scissors game in 4storyEG or UK,...
Rock Paper Scissors Bot Request
02/15/2010 - GW Bots - 3 Replies
Would it be possible for someone to make a bot that automatically plays rock paper scissors for lunar tokens?
Rock, paper, scissors.
11/21/2007 - Off Topic - 7 Replies
Originally posted by Clyps. "Ok, I understand that Scissors can beat Paper, and I get how Rock can beat Scissors, but there's no fucking way Paper can beat Rock. Paper is supposed to magically wrap around Rock leaving it immobile? Why the hell cant paper do this to scissors? Screw scissors, why can't paper do this to people?" "Why isn't notebook paper constantly suffocating students while they take notes in class? I'll tell you why, because paper can't beat anybody, a rock would tear that...
1-Day; Halloween/Rock,Paper,Scissors
11/03/2005 - Guild Wars - 3 Replies
If King Thorn ask's you which weapon you would choose to defeat him's, always choose Scissors, I was taking the Event at 13 and 16 O'Clock and he always had Paper. This only counts for today, cuz tomorrow theres no halloween anymore.



All times are GMT +1. The time now is 13:14.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.