Hi,
I am trying to make an app similar to the attached, where I have a menu bar.
When I click on an item in the menu bar, in this case Add Client, how can I make the add client window will appear with the contents of that window? Can someone please just list list a little example?
Thanks!
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class MenuExp extends JFrame {
public MenuExp() {
setTitle("Menu Example");
setSize(1024, 768);
// 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 fileMenu = new JMenu("File");
// JMenu editMenu = new JMenu("Edit");
menuBar.add(fileMenu);
//menuBar.add(editMenu);
// Create and add simple menu item to one of the drop down menu
JMenuItem addClientAction = new JMenuItem("Add Client");
JMenuItem editClientAction = new JMenuItem("Edit Client");
JMenuItem exitAction = new JMenuItem("Exit");
fileMenu.add(addClientAction);
fileMenu.add(editClientAction);
fileMenu.addSeparator();
fileMenu.add(exitAction);
// Add a listener to the New menu item. actionPerformed() method will
// invoked, if user triggred this menu item
addClientAction.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.out.println("You have clicked on the add new client");
}
});
}
public static void main(String[] args) {
MenuExp me = new MenuExp();
me.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
me.setVisible(true);
}
}
ASKER