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

home / study / engineering / computer science / computer science questions and a

ID: 3920331 • Letter: H

Question

home / study / engineering / computer science / computer science questions and answers / program in java, a menu bar. this will be added to a frame. the menus to be added are the followng: ...

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

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, it must adhere to the following :

- 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

Program in java,a menu bar.this will be added to a frame.the menus to be added are the following.
Program:
public class MenuExp extends JFrame {

public MenuExample() {

JSlider mySlider = new Slider(10, 100);
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();

String record;
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/task4DB?"
+ "user=root&password=123");
PreparedStatement st = con.prepareStatement("select * from record ");
ResultSet r1=st.executeQuery();

if(r1.next()) {

record++;
}


System.out.println( maxSalary);


}
public void addSlider(JSlider s, String description)
{
s.addChangeListener(listener);
JPanel panel = new JPanel();
panel.add(record);
panel.add(new JLabel(description));
sliderPanel.add(panel);
}
}

}