Create frame from JFrame
Design a class called MyJFrame to produce output as shown in Figures 1 – 7. This frame must be inherited from the class JFrame. The frame must contain only a title as shown in Figure 1
Figure 1
Create a menu bar object and set it in place. Add menu choices onto the menu bar as shown in Figure 2.
Figure 2
Add menu items to each menu choice as shown in Figure 3 and Figure 4. Place separators where indicated in the Figures.
.
Figure 3
For the menu choice Tools, create a cascading menu for the menu choice Edit. This submenu must contain menu items as shown in the Figure 4.
Figure 4
The following is an outline of the code for the class MyJFrame. You may consult your notes and class handouts for further information.
1. Use an interface to maintain constant values and generic methods
2. Use arrays to contain:
(a) The list of menu choices
(b) The list of menu items for the menu choices – File, Tool, and Edit.
// Area reserve for importing classes.
class MyJFrame extends JFrame
{
JMenuBar mbar;
JMenu jm;
JMenuItem mi;
MyJFrame(String title)
{
super(title);
mbar = new JMenuBar(); //Create menu bar and set it
setJMenuBar(mbar);
buildMenu(); // Call method which actually builds the menu
}
void buildMenu()
{
for (int i = 0; i <Constants. MENU.length; i++) // For each menu choice, create a menu choice object
{
jm = new JMenu(Constants.MENU[i]);
/* Determine the menu choice and create menu items for each menu
* choice and add each set of menu items to its respective menu choice
*/
switch(i)
{
case 0: // File
//Create separator or create file menu item and add each to the menu choice
break;
case 1: //Tool
/* First, check for the string Edit. When found, use it to create a sub menu
object. Next, create menu items, in this case – Copy and Paste as menu
items. Add these menu items to the sub menu. Finally, add this sub menu to
the menu choice Tool.
If the string is not Edit, then it must be a menu item for menu choice Tool.
Create each menu item objects, in this case – Sort and Search, and add each
to the menu choice Tool.
*/
break;
case 2: // Help, at this point no menu item will be attached
break;
default: // No action taken at this time
break;
}// End switch
mbar.add(jm); // Add each menu choice with its menu items to the menu bar.
}// End for
}// End build
}// End class MyJFrame
Need Solution email me: topsolutions8@gmail.com