Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Buttons in JAVA IN JAVA jGrasp MyMatchingGame.java I will rate well if the code is written correctly. In this game a student must match two

Buttons in JAVA IN JAVA jGrasp

MyMatchingGame.java I will rate well if the code is written correctly.

In this game a student must match two pictures together like the bottom example of matching the mascot to its school.

( I want to match movies to the main characters in the movies but I don't know how to add images to a button in jGrasp ).

Panel

Write a matching game program. Use BorderLayout with 3 panels. The north panel will have 5-6 buttons with an icon or words on each. Use Paint to resize all the pictures to the same dimensions. The center panel will have a title and/or directions. The south panel will have 5-6 buttons that can be matched to the north buttons. The order in the south will be different than the north. Output a statement or sound when the match is correct or not.

The Logic

In the panel you will need to keep track of the first button pressed, so when the second button is pressed, youll know if you have a match. Below is the easiest way to do it.

Create a private int, called choice, above the constructor (with the components).

Attach each button to its own Listener. When a top row button is selected, set choice to a number representing that button. In the matching bottom row buttons Listener, check choice and determine if the match was correct or not. Play your correct sound or incorrect sound. Then reset choice to 0.

You must select a top row button first, and then a bottom row button. See below:

private class NCSUListener implements ActionListener //attached to the NCSU logo in top row { public void actionPerformed (ActionEvent e) { choice = 1; //NCSU will be #1 } } private class NCSUMascotListener implements ActionListener //attached to NCSU mascot in bottom row { public void actionPerformed (ActionEvent e) { if (choice = = 1) goodSound1.play(); //a match else badSound1.play(); //not a match choice = 0; //reset for next attempt

} }

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

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions

Question

The presentations are full of management speak.

Answered: 1 week ago