Question: how do i fix the following design issues for the program: here are two design issues with the program. Never use the program name to

how do i fix the following design issues for the program:

here are two design issues with the program.

  1. Never use the program name to be extended or a part of the program. There should have been a separate class for generating the GUI interface.
  2. Limit the main () element coding to the basics. Have it call methods that do the work of the program, like entering values and displaying results.

************************

import java.awt.Color; import java.awt.Component;

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

//extends JMenuBar class public class Wk5AfetseM extends JMenuBar{ //create JMenu to add menu private JMenu menu;

public static void main(String[] para) { //create JFrame and provide title Menu Options JFrame frame = new JFrame("Menu Options"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //create sub menu using JMenu and add components JMenu jmenu = new JMenu("Sub Menu"); jmenu.add(new JMenuItem("Sub Menu A")); jmenu.add(new JMenuItem("Sub Menu B")); jmenu.add(new JMenuItem("Sub Menu C")); //create object that will indirectly instantiate constructor of JMenuBar Wk5AfetseM menu = new Wk5AfetseM("Menu"); //add menu item label menu.add(new JMenuItem("Menu Item 1")); menu.add(new JMenuItem("Menu Item 2")); menu.add(new JMenuItem("Menu Item 3")); //add submenu menu.add(jmenu); //create new panel in the layout JPanel jpanel = new JPanel(); //add object that instantiate JMenuBar to JPanel jpanel.add(menu); //set background color as blue jpanel.setBackground(Color.blue); //add panel to the frame frame.add(jpanel); frame.setVisible(true); //set frame size frame.setSize(300,250); }

//create constructor that also instantiate JMenuBar object public Wk5AfetseM(String title) { super(); //create menu and add to the menu menu = new JMenu(title); super.add(menu); }

//add overriding methods @Override public Component add(Component component) { //Add the JMenu by overriding return menu.add(component); }

@Override public JMenu add(JMenu jmenu) { //Add the JMenu by overriding add(..) return (JMenu) menu.add(jmenu); }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!