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

Program in JAVA, a menu bar. This will be added to a Frame. The menus to be adde

ID: 3920254 • Letter: P

Question

Program in JAVA, a menu bar. This will be added to a Frame. The menus to be added are the followng:

- Resident (hotkey T), with the following items:

1. Add (hotkey A)

2. Search (hotkey S)

- County (hotkey H), with the following items:

1. Add (hotkey A)

2. Search (hotkey S)

3. List (hotkey L)

4. Status (hotkey T)

- Politician (hotkey F), with the following items:

1.Add (hotkey A)

2. Search (hotkey S)

3. List (hotkey L)

4. Titles (hotkey T)

Then, create a Slider for the number of records to display in a Search:

- The minimum is 10 and the maximum is 100. Default value is 20.

- Have tick marks for every 10 records, and label every other tick mark.

Explanation / Answer

public class MenuExp extends JFrame {

     

    public MenuExample() {

         

        setTitle("Menu Example");

        setSize(150, 150);

         

        // Creates a menubar for a JFrame

        JMenuBar menuBar = new JMenuBar();

         

        // Add the menubar to the frame

        setJMenuBar(menuBar);

         

        // Define and add two drop down menu to the menubar

        JMenu resMenu = new JMenu("Resident");

        JMenu countMenu = new JMenu("County");

  

JMenu polMenu = new JMenu("Politician");

        menuBar.add(resMenu);

        menuBar.add(countMenu);

menuBar.add(polMenu);

         

        // Create and add simple menu item to one of the drop down menu

        JMenuItem radd = new JMenuItem("Add");

        JMenuItem rsearch = new JMenuItem("Search");

        JMenuItem cadd = new JMenuItem("Add");

        JMenuItem csearch = new JMenuItem("Search");

        JMenuItem clist = new JMenuItem("List");

        JMenuItem cstatus = new JMenuItem("Status");

  JMenuItem padd = new JMenuItem("Add");

JMenuItem psearch = new JMenuItem("Search");

JMenuItem plist = new JMenuItem("List");

JMenuItem ptitle = new JMenuItem("Title");

         

        // Create and add CheckButton as a menu item to one of the drop down

        // menu

        JCheckBoxMenuItem checkAction = new JCheckBoxMenuItem("Check Action");

  

resMenu.add(radd);

resMenu.add(rsearch);

countyMenu.add(cadd);

        countyMenu.add(csearch);

        countyMenu.add(clist);

countyMenu.add(cstatus);

polMenu.add(padd);

polMenu.add(psearch);

polMenu.add(plist);

polMenu.add(ptitle);

  

        // Add a listener to the New menu item. actionPerformed() method will

        // invoked, if user triggred this menu item

        newAction.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent arg0) {

                System.out.println("You have clicked on the new action");

            }

        });

    }

    public static void main(String[] args) {

        MenuExample me = new MenuExample();

        me.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        me.setVisible(true);

String str = e.getActionCommand();

    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote