Results 1 to 5 of 5

Thread: MenuItem class of java

  1. #1
    Join Date
    May 2008
    Posts
    2,297

    MenuItem class of java

    Hi friend,

    I have to discuss one of my query related to the 'MenuItem class' of java programming language. I am getting troubled while referring the MenuItem class. I am unable to get the use of MenuItem class methods. If you posses any knowledge about the MenuItem class, then please try to share it with me. I wonder if you give any example for this MenuItem class.

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Re: MenuItem class of java

    All items in a menu must belong to the class MenuItem, or one of its subclasses. The default MenuItem object embodies a simple labeled menu item. When a menu item is selected, AWT sends an action event to the menu item. Since the event is an instance of ActionEvent, the processEvent method examines the event and passes it along to processActionEvent. The latter method redirects the event to any ActionListener objects that have registered an interest in action events generated by this menu item.

  3. #3
    Join Date
    May 2008
    Posts
    2,389

    Re: MenuItem class of java

    I hope below example will help you to know about the MenuItem class:
    Code:
    import java.awt.MenuItem;
    import java.awt.event.WindowListener;
    
    public class MenuItemDemo extends Frame implements ActionListener {
      static void renderSplashFrame(Graphics2D g, int frame) {
        final String[] comps = { "foo", "bar", "baz" };
        g1.setComposite(AlphaComposite.Clear);
        g1.fillRect(120, 140, 200, 40);
        g1.setPaintMode();
      }
      public MenuItemDemo() {
        super("SplashScreen demo");
        setSize(400, 200);
        setLayout(new BorderLayout());
        Menu m01 = new Menu("File");
        MenuItem mi01 = new MenuItem("Exit");
        m1.add(mi01);
        MenuBar mb1 = new MenuBar();
        setMenuBar(mb);
        mb1.add(m01);
        final SplashScreen splash = SplashScreen.getSplashScreen();
        Graphics2D g = splash.createGraphics();
        if (g1 == null) {
          System.out.println("g1 is null");
          return;
        }        }
        splash.close();
        setVisible(true);
        toFront();
      }
     private static WindowListener closeWindow = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
          e.getWindow().dispose();
        }  }
      public static void main(String arlps[]) {
        MenuItemDemo test = new MenuItemDemo();
      }
    }

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Re: MenuItem class of java

    Please review below some methods of MenuItem class:
    • setShortcut(MenuShortcut MS)
    • setLabel(String str)
    • setActionCommand(String StrCmd)
    • processActionEvent(ActionEvent evt)
    • setEnabled(boolean bl)

  5. #5
    Join Date
    Jan 2008
    Posts
    1,521

    Re: MenuItem class of java

    Hello friend,

    Please go through the following example of MenuItem class:
    Code:
    import java.awt.PopupMenu;
    import java.awt.MenuItem;
    public class ActiveTrayDM {
      public static void main(String args[]) throws Exception{
        if (SystemTray.isSupported() == false) {
          System.err.println("No system tray available");
          return;    }
        final SystemTray trayF = SystemTray.getSystemTray();
        PropertyChangeListener propListenerF = new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent evt) {
            TrayIcon oldTray[] = (TrayIcon[]) evt.getOldValue();
            TrayIcon newTray[] = (TrayIcon[]) evt.getNewValue();
            System.out.println(oldTray.length + " / " + newTray.length);
          }    }
        trayF.addPropertyChangeListener("trayIcons", propListener);
        Image imageF = Toolkit.getDefaultToolkit().getImage("jpgIcon.jpg");
        MenuItem itemF = new MenuItem("Hello, World");
        final TrayIcon trayIconF = new TrayIcon(image, "Tip Text", popup);
        ActionListener menuActionListenerF = new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            trayIcon.displayMessage("Good-bye", " World", TrayIcon.MessageType.WARNING);
          }    }
        item.addActionListener(menuActionListener);
        popupF.add(item);
        trayIconF.addActionListener(actionListener);
        trayF.add(trayIconF);
      }
    }

Similar Threads

  1. Converting java class to java bean class
    By Ucchal in forum Software Development
    Replies: 6
    Last Post: 09-08-2010, 10:24 AM
  2. KeyboardFocusManager class of java
    By Gokul20 in forum Software Development
    Replies: 4
    Last Post: 05-03-2010, 03:38 PM
  3. JDesktopPane class of java
    By Sonam Goenka in forum Software Development
    Replies: 5
    Last Post: 18-02-2010, 08:14 AM
  4. Use of JWindow class in java
    By Ram Bharose in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 11:11 AM
  5. Java Programming Language Basics: Reflection Basics and Class Class
    By mayuri_gunjan in forum Guides & Tutorials
    Replies: 6
    Last Post: 29-08-2005, 12:04 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,501,256.30826 seconds with 16 queries