Gossip less direct code, here is mainly used to JMenuBar Jmenu,jmenuitem, JPopupMenu (right-click menu), see the document (javax.swing) can easily learn, the interface is a bit messy, but the basic use of these three classes
Import javax.swing.*; import java.awt.event.*; class Mymenu{jframe frame = new JFrame ("Right-click menu"); JMenuItem item1 = new JMenuItem ("submenu 1", New ImageIcon ("Close.gif")); JMenuItem item2 = new JMenuItem ("Sub-menu 2"); JMenuItem item3 = new JMenuItem ("Sub-menu 3"); JPopupMenu menu = new JPopupMenu (); JMenu m = new JMenu (); JPanel panel = new JPanel ();p ublic MyMenu () { menu.add (new JMenuItem ("select")); Menu.add (New JMenuItem ("Exit")); M.add (it EM1); M.add (ITEM2); Menu.add (m); Menu.add (ITEM3);p Anel.addmouselistener (New Mouseadapter () {public void mousereleased (MouseEvent e) {if ( E.ispopuptrigger ()) {menu.show (panel, E.getx (), e.gety ());}}) ;p anel.add (menu); Frame.add (panel); frame.setsize (300,300); frame.setvisible (True);}} Class Tester{public static void Main (String args[]) { new MyMenu ();}}
Swing Menu + Right-click menu + Two-level menu implementation