Help Me Here Please Dude!!! This Is Simple!! Please

here we go, wat i want is wen i click generate and it has the same value to the text field it will automatically says that Player One You Win! just like that. please take a look at generatebtn action performed method if statement! . please guyzz help me :)

import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;

public class Barney extends JFrame {

	private Random ran = new Random();

	private JLabel betlbl;
	private JLabel generatelbl;
	private JLabel playerOnelbl;
	private JLabel playerTwolbl;
	private JLabel playerThreelbl;

	private JButton generatebtn;
	private JButton placeBetbtn;

	private JTextField playerOnetf;
	private JTextField playerTwotf;
	private JTextField playerThreetf;

	public Barney() {
		super("Betting Game");
		setSize(600, 400);
		setResizable(false);
		setLocationRelativeTo(null);
		setLayout(null);
		
		betlbl = new JLabel("Betting Game");
		betlbl.setFont(new Font("Arial", Font.PLAIN, 30));
		
		generatelbl = new JLabel();
		generatelbl.setFont(new Font("Arial", Font.BOLD, 50));
		
		playerOnelbl = new JLabel("Player 1");
		playerOnelbl.setFont(new Font("Arial", Font.BOLD, 15));
	
		playerTwolbl = new JLabel("Player 2");
		playerTwolbl.setFont(new Font("Arial", Font.BOLD, 15));
		
		playerThreelbl = new JLabel("Player 3");
		playerThreelbl.setFont(new Font("Arial", Font.BOLD, 15));
		
		playerOnetf = new JTextField();
		playerTwotf = new JTextField();
		playerThreetf = new JTextField();
		
		generatebtn = new JButton("Generate");
		generatebtn.setVisible(false);
		generatebtn.addActionListener(
				new ActionListener() {
					public void actionPerformed(ActionEvent event) {
						int random = 1 + ran.nextInt(5);
						String rand = "" + random;
						generatelbl.setText(rand);
						String answer = "" + playerOnetf.getText();
						if (generatelbl.getText() == answer) {
							JOptionPane.showMessageDialog(null, "Player One Wins!");
						}
					}
				}
		);
		
		placeBetbtn = new JButton("Place All Bet");
		placeBetbtn.addActionListener(
				new ActionListener() {
					public void actionPerformed(ActionEvent event) {
						generatebtn.setVisible(true);
						placeBetbtn.setVisible(false);
						playerOnetf.setEditable(false);
						playerTwotf.setEditable(false);
						playerThreetf.setEditable(false);
					}
				}
		);
		
		add(betlbl);
		add(generatelbl);
		add(playerOnelbl);
		add(playerTwolbl);
		add(playerThreelbl);
		add(playerOnetf);
		add(playerTwotf);
		add(playerThreetf);
		add(generatebtn);
		add(placeBetbtn);
		
		
		
		
		betlbl.setBounds(215, 0, 300, 100);
		generatelbl.setBounds(290, 50, 300, 100);
		generatebtn.setBounds(260, 140, 100, 25);
		playerOnelbl.setBounds(48, 65, 300, 300);
		playerTwolbl.setBounds(280, 65, 300, 300);
		playerThreelbl.setBounds(500, 65, 300, 300);
		playerOnetf.setBounds(25, 230, 100, 25);
		playerTwotf.setBounds(262, 230, 100, 25);
		playerThreetf.setBounds(478, 230, 100, 25);
		placeBetbtn.setBounds(210, 280, 200, 25);
		
		
		
		
		
		
	}

	public static void main(String[] args) {
		Barney a = new Barney();
		a.setVisible(true);
	}

}

Comments

Sign In or Register to comment.