Question: actual code 1 import javax.swing.*; 2 import java.awt.*; 3 import java.awt.Color; 4 import javax.swing.ImageIcon.*; 5 6 7 public class Matching extends JPanel 8 { 9
actual code
1 import javax.swing.*; 2 import java.awt.*; 3 import java.awt.Color; 4 import javax.swing.ImageIcon.*; 5 6 7 public class Matching extends JPanel 8 { 9 10 private JButton b1; 11 private JButton b2; 12 private JButton b3; 13 private JButton b4; 14 private JButton b5; 15 private JButton b6; 16 private JButton b7; 17 private JButton b8; 18 private JButton b9; 19 private JButton b10; 20 private JButton b11; 21 22 23 24 public Matching() 25 { 26 b1 = new JButton("1"); 27 b2 = new JButton("2"); 28 b3 = new JButton("3"); 29 b4 = new JButton("4"); 30 b5 = new JButton("5"); 31 b6 = new JButton("TRUMP"); 32 b7 = new JButton("OSAMA"); 33 b8 = new JButton("GOAT"); 34 b9 = new JButton("HILLARY"); 35 b10 = new JButton("OBAMA"); 36 b11 = new JButton("Match People"); 37 38 //change layout manager 39 40 41 JPanel pNorth = new JPanel(); 42 43 pNorth.setLayout(new GridLayout(1,5)); 44 45 pNorth.add(b1); 46 pNorth.add(b2); 47 pNorth.add(b3); 48 pNorth.add(b4); 49 pNorth.add(b5); 50 51 b1.setIcon(new ImageIcon("OBAMA.jpg")); 52 b2.setIcon(new ImageIcon("OSAMA.jpg")); 53 b3.setIcon(new ImageIcon("TRUMP.jpg")); 54 b4.setIcon(new ImageIcon("GOAT.jpg")); 55 b5.setIcon(new ImageIcon("HILLARY.jpg")); 56 57 JPanel pSouth = new JPanel(); 58 59 pSouth.setLayout(new GridLayout(1,5)); 60 61 pSouth.add(b6); 62 pSouth.add(b7); 63 pSouth.add(b8); 64 pSouth.add(b9); 65 pSouth.add(b10); 66 67 b6.setFont(new Font("Comic Sans MS", Font.PLAIN, 35)); 68 b7.setFont(new Font("Comic Sans MS", Font.PLAIN, 35)); 69 b8.setFont(new Font("Comic Sans MS", Font.PLAIN, 35)); 70 b9.setFont(new Font("Comic Sans MS", Font.PLAIN, 35)); 71 b10.setFont(new Font("Comic Sans MS", Font.PLAIN, 35)); 72 73 b11.setFont(new Font("Comic Sans MS", Font.PLAIN, 50)); 74 75 b11.setBorderPainted(false); 76 77 setLayout(new BorderLayout()); 78 add(pNorth, BorderLayout.NORTH); 79 add(pSouth, BorderLayout.SOUTH); 80 add(b11, BorderLayout.CENTER); 81 82 validate(); 83 84 } 85 }
code with the main method
1 import javax.swing.*; 2 import java.awt.*; 3 import java.awt.Color; 4 import javax.swing.ImageIcon.*; 5 6 7 8 9 public class MatchingGame 10 { 11 public static void main(String[] args) 12 { 13 JFrame myframe = new JFrame("Matching Game"); 14 myframe.setLocation(100,200); 15 myframe.setSize(921, 500); 16 myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 17 18 19 myframe.setContentPane(new Matching()); 20 myframe.setVisible(true); 21 } 22 }
please finish this code. It is a matching game java code. when you correctly match person's picture and name, it should say correct with sound. i tried to attach pic of the code, but i don't know how. you have to add inner class.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
