Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

display dialog box by clicking a menu

Dear experts,

Is there a way to display a dialog box by clicking an option from a menu?

thank you
0
Halt123
Asked:
Halt123
5 Solutions
 
Manikandan ThiagarajanSenior consultantCommented:
0
 
Halt123Author Commented:
I've had a look through here but I am still unsure how to do it
0
 
objectsCommented:
In the action listener for the menu use:

JOptionPane.showMessageDialog(this, "my message");

some more info:

http://javaalmanac.com/egs/javax.swing/frame_Dialog.html
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
0
 
colr__Commented:
In the constructor for your code, you'll ned something like this. This just constructs the menu and adds an action listsner to the menu item

// Construct the menu:
JMenu menu = new JMenu();
// construct the menu items
JMenuItem item = new JMenuItem();
menu.add(item);
item.addActionListener(this);

The class in which this code is contained must implement ActionListsner's actionPerformed() method:

public void actionPerformed(ActionEvent e){
     if (e.getSource() instanceof JMenuItem)
          JOptionPane.showMessageDialog(this, "my message");
}

colr__
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now