Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a program that can display a GUI like the picture below. Hint: This progr

ID: 3777938 • Letter: C

Question

Create a program that can display a GUI like the picture below. Hint: This program is similar to the example we talked about in Chapter 18. "IP" and "2p" are two image buttons, these two images can be found in the zip file. Let's Play How Good Is Your Memory Try to figure out yourself A Player 1 Player 2 That's where you willeam

Explanation / Answer

import java.util.Scanner ; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import java.util.Random; public class MemoryGamer extends JFrame { static String files[] = {"1P.JPG", "2P.JPG",}; static JButton buttons[]; ImageIcon closedIcon; int numButtons; int alphaButtons; ImageIcon icons[]; Timer myTimer; int numClicks = 0; int alphaClicks=0; int oddClickIndex = 0; int currentIndex = 0; public MemoryGame() { setTitle("Memory Game"); // Specify an action for the close button. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create a BorderLayout manager. setLayout(new GridLayout(2, files.length)); closedIcon = new ImageIcon("closed.JPG"); numButtons = files.length * 2; alphaButtons = files1.length*2; buttons = new JButton[numButtons]; icons = new ImageIcon[numButtons]; buttons1 = new JButton[alphaButtons]; icons1= new ImageIcon[alphaButtons]; for (int i = 0, j = 0; i 3) { System.out.println("Wrong entry: you have to pick 1, 2 " + "or 3 matches") ; continue ; } if (totalMatches == 1 && matchesThisTurn > totalMatches) { System.out.println("You cannot pick " + matchesThisTurn + " matches: there is only one match left") ; continue ; } if (matchesThisTurn > totalMatches) { System.out.println("You cannot pick " + matchesThisTurn + " matches: there are only " + totalMatches + " matches left") ; continue ; } break ; } totalMatches -= matchesThisTurn ; matchesPreviousTurn = matchesThisTurn ; if (totalMatches == 0) { System.out.println("*** There are no more matches! ***") ; break ; } if (totalMatches == 1 && matchesThisTurn == 1) { System.out.println("*** There is only one match left, but " + "Player " + player + " already took one! ***") ; break ; } } System.out.println("*** The game is over! Player " + player + " Wins! ***") ; } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote