Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java help PLEASSEEEEE!! import java.awt.Font; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextArea; public class GUILLOfFortune extends

Java help PLEASSEEEEE!!

import java.awt.Font;

import java.awt.Toolkit;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.ArrayList;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JTextArea;

public class GUILLOfFortune extends JFrame {

JLabel instructions;

JButton submit;

JTextArea enterArea;

JLabel livesRemaining;

JLabel lettersEntered;

JLabel wordOutput;

boolean[] lettersCorrect = {false, false, false, false, false};

int lives;

String password;

ArrayList letters;

public static void main(String[] args) {

new GUILLOfFortune();

}

public GUILLOfFortune()

{

this.setDefaultCloseOperation(EXIT_ON_CLOSE);

int height = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();

int width = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();

this.setSize(width, height);

password = "super";

lives = 5;

letters = new ArrayList();

instructions = new JLabel("

Enter a letter to see if it's in the word!

" );

submit = new JButton("ENTER");

enterArea = new JTextArea();

livesRemaining = new JLabel("Lives: " + lives);

lettersEntered = new JLabel("

Letters Entered: " + letters + "

");

wordOutput = new JLabel("_ _ _ _ _");

wordOutput.setFont(new Font("Times", Font.BOLD, 20));

instructions.setSize(23*width/60, height/6);

submit.setSize(width/3, 50);

enterArea.setSize(width/3, 50);

livesRemaining.setSize(width/4, height/12);

lettersEntered.setSize(width/3, height/3);

wordOutput.setSize(width/2, height/6);

instructions.setLocation(width/15, 1);

submit.setLocation(width/2, height/2);

enterArea.setLocation(width/6, height/2);

livesRemaining.setLocation(11*width/15, 1);

lettersEntered.setLocation(17*width/30, height/20);

wordOutput.setLocation(width/3, height/3);

submit.addActionListener(new passwordButtonListener());

this.add(instructions);

this.add(submit);

this.add(enterArea);

this.add(livesRemaining);

this.add(lettersEntered);

this.add(wordOutput);

this.add(new JLabel());

this.setLocationRelativeTo(null);

setVisible(true);

}

private class passwordButtonListener implements ActionListener

{

public void actionPerformed(ActionEvent arg0) {

// code

}

}

}

Complete the ActionPerformed() method. It should do the following:

Take input from enterArea as one character. Ignore any input beyond a singular character.

Verify that the entered character has not already been entered/ submitted. If the character has not been entered, add it to the list of entered characters. Then, check to see if the entered character is a part of the password.

Change the text of wordOutput to reflect the correct letters that have been entered. If the letter was not a part of the word, subtract one life. Update the labels lettersEntered & livesRemaining to reflect these changes.

Check to see if the whole word has been entered. If so, the player has won.

Hint: lettersCorrect is an array of boolean variables which can be used to easily change wordOutput and verify if the word has been guessed.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 23rd European Conference Adbis 2019 Bled Slovenia September 8 11 2019 Proceedings Lncs 11695

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Aida Kamisalic Latific

1st Edition

3030287297, 978-3030287290

More Books

Students also viewed these Databases questions