Computer Guy
asked on
How can I make a window popup here with swing?
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.ActionListe ner;
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(addClientActi on);
fileMenu.add(editClientAct ion);
fileMenu.addSeparator();
fileMenu.add(exitAction);
// Add a listener to the New menu item. actionPerformed() method will
// invoked, if user triggred this menu item
addClientAction.addActionL istener(ne w ActionListener() {
public void actionPerformed(ActionEven t arg0) {
System.out.println("You have clicked on the add new client");
}
});
}
public static void main(String[] args) {
MenuExp me = new MenuExp();
me.setDefaultCloseOperatio n(JFrame.E XIT_ON_CLO SE);
me.setVisible(true);
}
}
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.ActionListe
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(addClientActi
fileMenu.add(editClientAct
fileMenu.addSeparator();
fileMenu.add(exitAction);
// Add a listener to the New menu item. actionPerformed() method will
// invoked, if user triggred this menu item
addClientAction.addActionL
public void actionPerformed(ActionEven
System.out.println("You have clicked on the add new client");
}
});
}
public static void main(String[] args) {
MenuExp me = new MenuExp();
me.setDefaultCloseOperatio
me.setVisible(true);
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
JDialog in conjunction with JOptionPane gives you the facility to create custom interfaces yes. Take a look at the API lit for JDialog for more detail.
ASKER
Thanks!!!
Also, what is your opinion on using NetBeans for something like this?
I have toyed with it, but for some reason it seems as if the code style is A LOT different than doing it this way.
Also, what is your opinion on using NetBeans for something like this?
I have toyed with it, but for some reason it seems as if the code style is A LOT different than doing it this way.
I don't know about Netbeans, sorry. I don't use IDEs. ;(
>> Also, what is your opinion on using NetBeans for something like this?
I don't use NetBeans neither.
But I'd like to say that code generation is all a matter of taste.
You can write functionally identical code in a dozen of ways.
If NetBeans generates code that you can read and understand it's okay.
If it doesn't then don't use it and write your own.
I don't use NetBeans neither.
But I'd like to say that code generation is all a matter of taste.
You can write functionally identical code in a dozen of ways.
If NetBeans generates code that you can read and understand it's okay.
If it doesn't then don't use it and write your own.
ASKER