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

If anyone can help writing this program? Tasks and Rubric ctivit astermind ckage

ID: 3598956 • Letter: I

Question


If anyone can help writing this program?

Tasks and Rubric ctivit astermind ckage Mastermind.java l. Add to mcthod main) a. Instantiate an instance of class MastermindUi, passing the reference object of class Game as an argument core package ame.java userlnterface 1. In the customer constructor, comment out the call the method play( ackage astermindUi.java 1. Add member variables of type a. Game game; b. CodebreakerUi codebreakerUi c. CodemakerUi codemakerUi; d. JFrame frame; e. JMenuBar menuBar f. JMenu gameMenu; g. JMenu helpMenu; h. JMenultem newGameMenultem i. JMenultem exitMenultem; j. JMenultem aboutMenultem; k. JMcnultem rulesMenultem 2. A custom constructor should be defined that receives a parameter of type Game class a. Set member variable of type class Game to the parameter passed in b. Instantiate the member variable of class CodebreakerUi passing as an argument to the constructor the instance of class Codebreaker in class Game (hint: use the getter!) c. Instantiate the member variable of class CodemakerUi passing as an argument to the constructor the instance of class Codemaker in class Game (hint: use the getter!) d. call method initComponents) 3. A method initComponents) should initialize all the components for the UI and be called from the constructor a. Set the default size of the JFrame b. Set the default close operation of the JFrame c. Use default layout manager BorderLayout d. Set up the JMenuBar i. JMenu Game should be added to the JMenuBar ii. JMenuItems New Game and Exit should be added to the JMenu Game iii. JMenu Help should be added to the JMenuBar iiii. JMenultems About and Game Rules should be added to the JMenu Help c. JMcnuBar should be sct on the JFramc f. Add the CodemakerUi JPanels to the JFrame using the getters defined in the class g. Add the CodebreakerUi JPanels to the JFrame using the getters defined in the class h. Set the visibility of the JFrame (hint: this should ALWAYS be the last step on a UI) Write an inner class to create an ActionListener that is registered to the JMcnultcm with thc text Exit t should a. Display a JOptionPane message confirming the user wants to exit using method showConfirmDialog) b. If yes, exit the application by calling method System.exit passing the value of 0 as an argument c. If no, do not cxit thc application 5. Write an inner class to create an ActionListener that is registered to the JMenultem with the text About using method showMessageDialog0; it should a. Display a JQntionPane message informing the user:

Explanation / Answer

package view;

import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class Frame2 extends JFrame {
private JMenuBar menuBar = new JMenuBar();
private JMenu menuFile = new JMenu();
private JMenuItem exitMenuItem = new JMenuItem();
private JMenuItem newGameMenuItem = new JMenuItem();
private JMenu menuHelp = new JMenu();
private JMenuItem menuHelpAbout = new JMenuItem();
private JPanel jPanel1 = new JPanel();
private JPanel jPanel2 = new JPanel();
private JPanel jPanel3 = new JPanel();
private JPanel jPanel4 = new JPanel();
private JLabel jLabel1 = new JLabel();

public Frame2() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}

private void jbInit() throws Exception {
this.setJMenuBar( menuBar );
this.getContentPane().setLayout( null );
this.setSize(new Dimension(929, 499));
menuFile.setText( "Game" );
newGameMenuItem.setText("New Game");
exitMenuItem.setText( "Exit" );
exitMenuItem.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent ae ) { fileExit_ActionPerformed( ae ); } } );
newGameMenuItem.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent ae ) { } } );
menuHelp.setText( "Help" );
menuHelpAbout.setText( "About" );
menuHelpAbout.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent ae ) { helpAbout_ActionPerformed( ae ); } } );
jPanel1.setBounds(new Rectangle(10, 5, 795, 35));
jPanel2.setBounds(new Rectangle(10, 55, 475, 320));
jPanel3.setBounds(new Rectangle(510, 50, 290, 325));
jPanel4.setBounds(new Rectangle(5, 385, 805, 50));
jLabel1.setText("Codebreaker attempts");
jLabel1.setBounds(new Rectangle(5, 50, 150, 15));
menuFile.add( newGameMenuItem);
menuFile.add( exitMenuItem );
menuBar.add( menuFile );
menuHelp.add( menuHelpAbout );
menuBar.add( menuHelp );
this.getContentPane().add(jPanel4, null);
this.getContentPane().add(jPanel3, null);
this.getContentPane().add(jPanel2, null);
this.getContentPane().add(jPanel1, null);
this.getContentPane().add(jLabel1, null);
}

void fileExit_ActionPerformed(ActionEvent e) {
System.exit(0);
}

void helpAbout_ActionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(this, new Frame2_AboutBoxPanel1(), "About", JOptionPane.PLAIN_MESSAGE);
}
  
public static void main(String args[]){
Frame2 frame=new Frame2();
frame.setTitle("Mastermind");
frame.setVisible(true);
}
}

package view;

import java.awt.Dimension;

import java.awt.Rectangle;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Frame4 extends JFrame {
private JButton jButton1 = new JButton();
private JLabel jLabel1 = new JLabel();

public Frame4() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}

private void jbInit() throws Exception {
this.getContentPane().setLayout( null );
this.setSize(new Dimension(400, 181));
this.setTitle( "Message" );
this.setBounds(new Rectangle(100, 100, 400, 181));
jButton1.setText("OK");
jButton1.setBounds(new Rectangle(135, 90, 90, 35));
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jLabel1.setText("Let's Play Mastermind");
jLabel1.setBounds(new Rectangle(130, 30, 160, 30));
this.getContentPane().add(jLabel1, null);
this.getContentPane().add(jButton1, null);
}

private void jButton1_actionPerformed(ActionEvent e) {
Frame2 frame=new Frame2();
frame.setVisible(true);
frame.setTitle("Mastermind");
}
  
public static void main(String args[]){
Frame4 fm=new Frame4();
fm.setVisible(true);
}
}