import javax.swing.*; //import java.beans.*; //Property change stuff import java.awt.*; import java.awt.event.*; /* * MyMenuDialog.java is a simple Java application to demo display * of a dialog box. */ public class MyMenuDialog extends JPanel implements ActionListener{ JFrame nsFrame; /** Creates the GUI shown inside the frame's content pane. */ public MyMenuDialog(JFrame frame) { JMenuBar menuBar; JMenu menu, submenu; JMenuItem menuItem; //Create the menu bar. menuBar = new JMenuBar(); //Build the first menu. menu = new JMenu("Dialog"); menuBar.add(menu); //a group of JMenuItems menuItem = new JMenuItem("Pop dialog"); menu.add(menuItem); menu = new JMenu("About"); menuBar.add(menu); JButton DBut = new JButton ("Pane content"); menuItem.setActionCommand("DB"); menuItem.addActionListener(this); nsFrame=frame; add(DBut); nsFrame.setJMenuBar(menuBar); } public void actionPerformed(ActionEvent e) { if ("DB".equals(e.getActionCommand())) //ok dialog JOptionPane.showMessageDialog(nsFrame, "Some approriate message."); } /** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread. */ private static void createAndShowGUI() { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); //Create and set up the window. JFrame frame = new JFrame("MyMenuDialog"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create and set up the content pane. MyMenuDialog newContentPane = new MyMenuDialog(frame); newContentPane.setOpaque(true); //content panes must be opaque newContentPane.setBorder( BorderFactory.createEmptyBorder(20,30,20,30)); //T,L,B,R frame.setContentPane(newContentPane); //Display the window. frame.pack(); frame.setVisible(true); } public static void main(String[] args) { //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }