⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 menu.java

📁 this gcc-g++-3.3.1.tar.gz is a source file of gcc, you can learn more about gcc through this codes f
💻 JAVA
字号:
/* Menu.java -- A Java AWT Menu   Copyright (C) 1999, 2002 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package java.awt;import java.awt.peer.MenuPeer;import java.awt.peer.MenuItemPeer;import java.awt.peer.MenuComponentPeer;import java.io.Serializable;import java.util.Vector;import java.util.Enumeration;/**  * This class represents a pull down or tear off menu in Java's AWT.  *  * @author Aaron M. Renn (arenn@urbanophile.com)  */public class Menu extends MenuItem implements MenuContainer, Serializable{/* * Static Variables */// Serialization Constantprivate static final long serialVersionUID = -8809584163345499784L;/*************************************************************************//* * Instance Variables *//**  * @serial The actual items in the menu  */private Vector items = new Vector();/**  * @serial Flag indicating whether or not this menu is a tear off  */private boolean isTearOff;/**  * @serial Indicates whether or not this is a help menu.  */private boolean isHelpMenu;// From the serialization spec.  FIXME: what should it be?private int menuSerializedDataVersion;static final MenuItem separator = new MenuItem("-");/*************************************************************************//* * Constructors *//**  * Initializes a new instance of <code>Menu</code> with no label and that  * is not a tearoff;  *  * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.  */publicMenu(){}/*************************************************************************//**  * Initializes a new instance of <code>Menu</code> that is not a tearoff and  * that has the specified label.  *  * @param label The menu label.  *  * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.  */publicMenu(String label){  this(label, false);}/*************************************************************************//**  * Initializes a new instance of <code>Menu</code> with the specified  * label and tearoff status.  *  * @param label The label for this menu  * @param isTearOff <code>true</code> if this menu is a tear off menu,  * <code>false</code> otherwise.  *  * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.  */publicMenu(String label, boolean isTearOff){  super(label);  this.isTearOff = isTearOff;  if (label.equals("Help"))    isHelpMenu = true;  if (GraphicsEnvironment.isHeadless())    throw new HeadlessException ();}/*************************************************************************//* * Instance Methods *//**  * Tests whether or not this menu is a tearoff.  *  * @return <code>true</code> if this menu is a tearoff, <code>false</code>  * otherwise.  */public booleanisTearOff(){  return(isTearOff);}/*************************************************************************//**  * Returns the number of items in this menu.  *  * @return The number of items in this menu.  */public intgetItemCount(){  return(items.size());} /*************************************************************************//**  * Returns the number of items in this menu.  *  * @return The number of items in this menu.  *  * @deprecated This method is deprecated in favor of <code>getItemCount()</code>.  */public intcount(){  return(items.size());} /*************************************************************************//**  * Returns the item at the specified index.  *  * @return The item at the specified index.  *  * @exception ArrayIndexOutOfBoundsException If the index value is not valid.  */public MenuItemgetItem(int index){  return((MenuItem)items.elementAt(index));}/*************************************************************************//**  * Adds the specified item to this menu.  If it was previously part of  * another menu, it is first removed from that menu.  *  * @param item The new item to add.  *  * @return The item that was added.  */public MenuItemadd(MenuItem item){  items.addElement(item);  if (item.parent != null)    {      item.parent.remove(item);    }  item.parent = this;  if (peer != null)    {      MenuPeer mp = (MenuPeer) peer;      mp.addItem(item);    }  return item;}/*************************************************************************//**  * Add an item with the specified label to this menu.  *  * @param label The label of the menu item to add.  */public voidadd(String label){  add(new MenuItem(label));}/*************************************************************************//**  * Inserts the specified menu item into this menu at the specified index.  *  * @param item The menu item to add.  * @param index The index of the menu item.  *  * XXX: FIXME  *  * @exception IllegalArgumentException If the index is less than zero.  * @exception ArrayIndexOutOfBoundsException If the index is otherwise invalid.  */public voidinsert(MenuItem item, int index){  if (index < 0)    throw new IllegalArgumentException("Index is less than zero");  items.insertElementAt(item, index);  MenuPeer mp = (MenuPeer)getPeer();  // FIXME: Need to add a peer method here.//    if (mp != null)//      mp.insertItem(item, index);}/*************************************************************************//**  * Inserts an item with the specified label into this menu at the specified index.  *  * @param label The label of the item to add.  * @param index The index of the menu item.  *  * @exception IllegalArgumentException If the index is less than zero.  * @exception ArrayIndexOutOfBoundsException If the index is otherwise invalid.  */public voidinsert(String label, int index){  insert(new MenuItem(label), index);}/*************************************************************************//**  * Adds a separator bar at the current menu location.  */public voidaddSeparator(){  add(separator);}/*************************************************************************//**  * Inserts a separator bar at the specified index value.  *  * @param index The index at which to insert a separator bar.  *  * XXX: FIXME  *  * @exception IllegalArgumentException If the index is less than zero.  * @exception ArrayIndexOutOfBoundsException If the index is otherwise invalid.  */public voidinsertSeparator(int index){  insert(separator, index);}/*************************************************************************//**  * Deletes the item at the specified index from this menu.  *  * @param index The index of the item to remove.  *   * @exception ArrayIndexOutOfBoundsException If the index is otherwise invalid.  */public synchronized voidremove(int index){  items.removeElementAt(index);  MenuPeer mp = (MenuPeer)getPeer();  if (mp != null)    mp.delItem(index);}/*************************************************************************//**  * Removes the specifed item from the menu.  If the specified component  * does not exist, this method does nothing. // FIXME: Right?  *  * @param item The component to remove.  */public voidremove(MenuComponent item){  int index = items.indexOf(item);  if (index == -1)    return;  remove(index);}/*************************************************************************//**  * Removes all the elements from this menu.  */public synchronized voidremoveAll(){  int count = getItemCount();  for(int i = 0; i < count; i++)    {      // We must always remove item 0.      remove(0);    }}/*************************************************************************//**  * Creates the native peer for this object.  */public voidaddNotify(){  if (peer != null)    peer = getToolkit().createMenu(this);  super.addNotify ();}/*************************************************************************//**  * Destroys the native peer for this object.  */public voidremoveNotify(){  super.removeNotify();}/*************************************************************************//**  * Returns a debugging string for this menu.  *  * @return A debugging string for this menu.  */public StringparamString(){  return (",isTearOff=" + isTearOff + ",isHelpMenu=" + isHelpMenu	  + super.paramString());}// Accessibility API not yet implemented.// public AccessibleContext getAccessibleContext()} // class Menu

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -