package javaapplication6;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JMenuDemo extends JFrame implements
ActionListner
{
public
void actionPerformed (ActionEvent e)
{
System.out.println(e.getActionCommand());
}
public
JMenuDemo()
{
super("JMenu Demo");
JMenuBar jmb=new JMenuBar();
JMenu
file=new JMenu("File ");
JMenuItem item1,item2;
file.add(item1=new JMenuItem("New"));
file.add(item1=new JMenuItem("Open"));
file.addSeparator();
file.add(item1=new JMenuItem("Close"));
jmb.add(file);
JMenu
edit=new JMenu("Edit");
edit.add(item2=new JMenuItem("Copy"));
edit.add(item2= new JMenuItem("Past"));
item2.setHorizontalTextPosition(JMenuItem.LEFT);
jmb.add(edit);
setJMenuBar(jmb);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public
static void main(String[] args)
{
JMenuDemo ob=new JMenuDemo();
ob.setSize(300,300);
ob.setVisible(true);
}
}
Output:
No comments:
Post a Comment