Import the JMenuBar class from java.swing.

>>> from javax.swing import JJMenuBar

Create an instance of it.

Import and create an instance nf JFrame.

>>> from javax.swing import JFrame >>> frame = JFrame()

Set the JMenuBar property of the frame to the JMenuBar instance.

>>> frame.JJMenuBar = bar >>> frame.visible=1

Now that we have a menubar added in the frame, we need to add a menu to it. Create a menu (JMenu), and add it to the menraar.

>>> from javax.swing import JMenu >>> fruitMenu = JMenu("Fruit") >>> bar.add(fruitMenu) >>> frame.pack()

Add menu items to the menu.

>>> from javax.swing import JMenultem >>> fruitMenu.add(Menultem("Apple") ) >>> frui tMenu.add(JMenultem("Pear") ) >>> frui tMenu.add(JMenultem("Peaches") )

Was this article helpful?

0 0

Post a comment