java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPopupMenu
- 所有已实现的接口:
-
ImageObserver,MenuContainer,Serializable,Accessible,MenuElement
- 直接已知的子类:
-
BasicComboPopup
@JavaBean(defaultProperty="UI", description="A small window that pops up and displays a series of choices.") public class JPopupMenu extends JComponent implements Accessible, MenuElement
弹出菜单的实现 - 一个弹出并显示一系列选择项的小窗口。
JPopupMenu 用于用户在菜单栏上选择项目时出现的菜单。当用户选择激活它的菜单项时,也用于“向右拉”菜单。最后,JPopupMenu 也可用于任何您希望菜单出现的地方。例如,当用户在指定区域右键单击时。
有关使用弹出菜单的信息和示例,请参阅Java教程中的如何使用菜单
警告: Swing 不是线程安全的。有关更多信息,请参阅Swing的线程策略。
警告: 该类的序列化对象将不兼容未来的Swing版本。当前的序列化支持适用于短期存储或在运行相同Swing版本的应用程序之间的RMI。从1.4开始,已将所有JavaBeans的长期存储支持添加到java.beans包中。请参阅XMLEncoder。
- 自版本:
- 1.2
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class该类实现了对JPopupMenu类的辅助功能支持。static class弹出菜单特定的分隔符。Nested classes/interfaces declared in class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces declared in class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces declared in class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
Fields declared in class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields declared in class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields declared in interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription创建一个具有指定文本的新菜单项,并将其附加到此菜单的末尾。将一个新的菜单项附加到菜单的末尾,该菜单项分派指定的Action对象。将指定的菜单项附加到此菜单的末尾。void向弹出菜单添加一个MenuKeyListener。void添加一个PopupMenu监听器。void在菜单末尾添加一个新的分隔符。protected PropertyChangeListener返回一个正确配置的PropertyChangeListener,它会在Action发生更改时更新控件。protected JMenuItem工厂方法,为添加到JPopupMenu的Actions创建JMenuItem。protected void通知PopupMenuListeners此弹出菜单已取消。protected void通知PopupMenuListener们此弹出菜单将变为不可见。protected void通知PopupMenuListener们此弹出菜单将变为可见。获取与此JPopupMenu关联的AccessibleContext。返回此JPopupMenu组件。getComponentAtIndex(int i) 已弃用。int返回指定组件的索引。static boolean获取defaultLightWeightPopupEnabled属性,默认为true。返回作为此弹出菜单的“调用者”的组件。getLabel()返回弹出菜单的标签。返回弹出菜单边框与其容器之间的边距(以像素为单位)。返回添加到此JPopupMenu中的所有MenuKeyListener的数组。返回添加到此JMenuItem中的所有PopupMenuListener的数组。返回处理单个选择的模型对象。返回包含此菜单组件子菜单的MenuElement数组。getUI()返回呈现此组件的外观(L&F)对象。返回呈现此组件的L&F类的名称。void将指定的组件插入到给定位置的菜单中。void在给定位置为指定的Action对象插入一个菜单项。boolean检查是否应绘制边框。boolean获取lightWeightPopupEnabled属性。boolean如果MouseEvent被当前安装的UI视为弹出触发器,则返回true。boolean如果弹出菜单可见(当前正在显示),则返回true。voidmenuSelectionChanged(boolean isIncluded) 当菜单栏选择更改以激活或停用此菜单时发送消息。voidpack()布局容器,使其使用显示内容所需的最小空间。protected void如果borderPainted属性为true,则绘制弹出菜单的边框。protected String返回此JPopupMenu的字符串表示形式。protected voidprocessKeyEvent(KeyEvent evt) 处理键盘事件,如助记键和加速键。voidprocessKeyEvent(KeyEvent e, MenuElement[] path, MenuSelectionManager manager) 处理从MenuSelectionManager转发的键事件,并根据需要更改菜单选择,使用MenuSelectionManager的API。voidprocessMouseEvent(MouseEvent event, MenuElement[] path, MenuSelectionManager manager) 此方法是为了符合MenuElement接口而需要的,但未实现。voidremove(int pos) 从此弹出菜单中删除指定索引处的组件。void从弹出菜单中删除MenuKeyListener。void删除PopupMenu监听器。voidsetBorderPainted(boolean b) 设置是否应绘制边框。static voidsetDefaultLightWeightPopupEnabled(boolean aFlag) 设置lightWeightPopupEnabled属性的默认值。voidsetInvoker(Component invoker) 设置此弹出菜单的“调用者” - 要显示弹出菜单的组件。void设置弹出菜单的标签。voidsetLightWeightPopupEnabled(boolean aFlag) 设置lightWeightPopupEnabled属性的值,默认为true。voidsetLocation(int x, int y) 使用x、y坐标设置弹出菜单的左上角位置。voidsetPopupSize(int width, int height) 使用指定的宽度和高度设置弹出窗口的大小。void使用Dimension对象设置弹出窗口的大小。voidsetSelected(Component sel) 设置当前选定的组件,这将导致选择模型的更改。void设置处理单个选择的模型对象。voidsetUI(PopupMenuUI ui) 设置呈现此组件的外观(L&F)对象。voidsetVisible(boolean b) 设置弹出菜单的可见性。void在调用者组件的坐标空间中的位置x,y处显示弹出菜单。voidupdateUI()将UI属性重置为当前外观的值。Methods declared in class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction, updateMethods declared in class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeMethods declared in class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
JPopupMenu
public JPopupMenu()构造一个没有“调用者”的JPopupMenu。 -
JPopupMenu
构造具有指定标题的JPopupMenu。- 参数:
-
label- UI可能用来显示为弹出菜单标题的字符串。
-
-
Method Details
-
setDefaultLightWeightPopupEnabled
public static void setDefaultLightWeightPopupEnabled(boolean aFlag) 设置lightWeightPopupEnabled属性的默认值。- 参数:
-
aFlag- 如果弹出菜单可以轻量级,则为true,否则为false - 参见:
-
getDefaultLightWeightPopupEnabled
public static boolean getDefaultLightWeightPopupEnabled()获取defaultLightWeightPopupEnabled属性,默认为true。- 返回:
-
defaultLightWeightPopupEnabled属性的值 - 参见:
-
getUI
返回呈现此组件的外观(L&F)对象。- 覆盖:
-
getUI在类JComponent中 - 返回:
-
渲染此组件的
PopupMenuUI对象
-
setUI
@BeanProperty(hidden=true, visualUpdate=true, description="The UI object that implements the Component\'s LookAndFeel.") public void setUI(PopupMenuUI ui) 设置呈现此组件的外观(L&F)对象。- 参数:
-
ui- 新的PopupMenuUIL&F对象 - 参见:
-
updateUI
public void updateUI()将UI属性重置为当前外观的值。- 覆盖:
-
updateUI在类JComponent中 - 参见:
-
getUIClassID
返回呈现此组件的L&F类的名称。- 覆盖:
-
getUIClassID在类JComponent中 - 返回:
- 字符串"PopupMenuUI"
- 参见:
-
processKeyEvent
处理键盘事件,如助记键和加速键。- 覆盖:
-
processKeyEvent在类JComponent中 - 参数:
-
evt- 要处理的键盘事件 - 参见:
-
getSelectionModel
返回处理单选的模型对象。- 返回:
-
selectionModel属性 - 参见:
-
setSelectionModel
@BeanProperty(bound=false, expert=true, description="The selection model for the popup menu") public void setSelectionModel(SingleSelectionModel model) 设置处理单选的模型对象。- 参数:
-
model- 新的SingleSelectionModel - 参见:
-
add
将指定的菜单项追加到此菜单的末尾。- 参数:
-
menuItem- 要添加的JMenuItem - 返回:
-
添加的
JMenuItem
-
add
使用指定的文本创建一个新的菜单项,并将其追加到此菜单的末尾。- 参数:
-
s- 要添加的菜单项的字符串 - 返回:
-
使用
s创建的新JMenuItem
-
add
在菜单的末尾添加一个新的菜单项,该菜单项分派指定的Action对象。- 参数:
-
a- 要添加到菜单中的Action - 返回:
- 新的菜单项
- 参见:
-
createActionComponent
工厂方法,为添加到JPopupMenu的Actions创建JMenuItem。- 参数:
-
a- 要添加的菜单项的Action - 返回:
- 新的菜单项
- 自:
- 1.3
- 参见:
-
createActionChangeListener
返回一个正确配置的PropertyChangeListener,当Action发生更改时更新控件。- 参数:
-
b- 要创建监听器的菜单项 - 返回:
-
一个正确配置的
PropertyChangeListener
-
remove
public void remove(int pos) 从此弹出菜单中删除指定索引处的组件。- 覆盖:
-
remove在类Container中 - 参数:
-
pos- 要删除的项目的位置 - 抛出:
-
IllegalArgumentException- 如果pos的值小于0,或者如果pos的值大于项目数 - 参见:
-
setLightWeightPopupEnabled
@BeanProperty(bound=false, expert=true, description="Determines whether lightweight popups are used when possible") public void setLightWeightPopupEnabled(boolean aFlag) 设置lightWeightPopupEnabled属性的值,默认为true。默认情况下,当外观显示弹出菜单时,它可以选择使用轻量级(全Java)弹出菜单。轻量级弹出窗口比重量级(本机对等体)窗口更高效,但轻量级和重量级组件在GUI中不搭配。如果您的应用程序混合使用轻量级和重量级组件,则应禁用轻量级弹出菜单。某些外观可能始终使用重量级弹出菜单,无论此属性的值如何。- 参数:
-
aFlag-false以禁用轻量级弹出菜单 - 参见:
-
isLightWeightPopupEnabled
public boolean isLightWeightPopupEnabled()获取lightWeightPopupEnabled属性。- 返回:
-
lightWeightPopupEnabled属性的值 - 参见:
-
getLabel
返回弹出菜单的标签- 返回:
- 包含弹出菜单标签的字符串
- 参见:
-
setLabel
设置弹出菜单的标签。不同的外观可能选择显示或不显示此标签。- 参数:
-
label- 指定弹出菜单的标签的字符串 - 参见:
-
addSeparator
public void addSeparator()在菜单的末尾添加一个新的分隔符。 -
insert
在给定位置插入指定Action对象的菜单项。- 参数:
-
a- 要插入的Action对象 -
index- 指定要插入Action的位置,其中0是第一个 - 抛出:
-
IllegalArgumentException- 如果index小于0 - 参见:
-
insert
在给定位置将指定组件插入菜单中。- 参数:
-
component- 要插入的Component -
index- 指定要插入组件的位置,其中0是第一个 - 抛出:
-
IllegalArgumentException- 如果index小于0
-
addPopupMenuListener
添加一个PopupMenu监听器。- 参数:
-
l- 要添加的PopupMenuListener
-
removePopupMenuListener
删除一个PopupMenu监听器。- 参数:
-
l- 要移除的PopupMenuListener
-
getPopupMenuListeners
返回添加到此JMenuItem的所有PopupMenuListener的数组。- 返回:
-
所有已添加的
PopupMenuListener或空数组(如果未添加任何监听器) - 自:
- 1.4
-
addMenuKeyListener
向弹出菜单添加一个MenuKeyListener。- 参数:
-
l- 要添加的MenuKeyListener - 自:
- 1.5
-
removeMenuKeyListener
从弹出菜单中删除一个MenuKeyListener。- 参数:
-
l- 要移除的MenuKeyListener - 自:
- 1.5
-
getMenuKeyListeners
返回添加到此JPopupMenu的所有MenuKeyListener的数组。- 返回:
-
所有已添加的
MenuKeyListener或空数组(如果未添加任何监听器) - 自:
- 1.5
-
firePopupMenuWillBecomeVisible
protected void firePopupMenuWillBecomeVisible()通知PopupMenuListener,此弹出菜单将变为可见。 -
firePopupMenuWillBecomeInvisible
protected void firePopupMenuWillBecomeInvisible()通知PopupMenuListener,此弹出菜单将变为不可见。 -
firePopupMenuCanceled
protected void firePopupMenuCanceled()通知PopupMenuListeners,此弹出菜单已取消。 -
pack
public void pack()对容器进行布局,以便使用显示内容所需的最小空间。 -
setVisible
设置弹出菜单的可见性。- 覆盖:
-
setVisible在类JComponent中 - 参数:
-
b- true表示使弹出菜单可见,false表示隐藏 - 参见:
-
isVisible
public boolean isVisible()如果弹出菜单可见(当前正在显示),则返回true。 -
setLocation
使用x、y坐标设置弹出菜单左上角的位置。该方法更改与几何相关的数据。因此,本地窗口系统可能会忽略此类请求,或者可能会修改请求的数据,以便
JPopupMenu对象被放置和调整大小,以便与桌面设置紧密对应。- 覆盖:
-
setLocation在类Component中 - 参数:
-
x- 弹出菜单在屏幕坐标空间中的新位置的x坐标 -
y- 弹出菜单在屏幕坐标空间中的新位置的y坐标 - 参见:
-
getInvoker
返回调用此弹出菜单的组件。- 返回:
-
显示弹出菜单的
Component
-
setInvoker
@BeanProperty(bound=false, expert=true, description="The invoking component for the popup menu") public void setInvoker(Component invoker) 设置此弹出菜单的调用者 - 弹出菜单应在其中显示的组件。- 参数:
-
invoker- 显示弹出菜单的Component
-
show
在组件调用者的坐标空间中的位置x、y处显示弹出菜单。- 参数:
-
invoker- 弹出菜单应出现在其空间中的组件 -
x- 弹出菜单应显示的invoker坐标空间中的x坐标 -
y- 弹出菜单应显示的invoker坐标空间中的y坐标
-
getComponentAtIndex
Deprecated.replaced byContainer.getComponent(int)返回指定索引处的组件。- 参数:
-
i- 组件的索引,其中0是第一个 - 返回:
-
该索引处的
Component
-
getComponentIndex
返回指定组件的索引。- 参数:
-
c- 要查找的Component - 返回:
- 组件的索引,其中0是第一个;如果未找到组件则返回-1
-
setPopupSize
使用Dimension对象设置弹出窗口的大小。这等效于setPreferredSize(d)。- 参数:
-
d- 指定此组件新大小的Dimension
-
setPopupSize
@BeanProperty(description="The size of the popup menu") public void setPopupSize(int width, int height) 将弹出窗口的大小设置为指定的宽度和高度。这等效于setPreferredSize(new Dimension(width, height))。- 参数:
-
width- 弹出窗口的新宽度(以像素为单位) -
height- 弹出窗口的新高度(以像素为单位)
-
setSelected
@BeanProperty(expert=true, hidden=true, description="The selected component on the popup menu") public void setSelected(Component sel) 设置当前选定的组件,这将导致选择模型的更改。- 参数:
-
sel- 要选择的Component
-
isBorderPainted
public boolean isBorderPainted()检查是否应绘制边框。- 返回:
- 如果绘制边框则返回true,否则返回false
- 参见:
-
setBorderPainted
@BeanProperty(bound=false, description="Is the border of the popup menu painted") public void setBorderPainted(boolean b) 设置是否应绘制边框。- 参数:
-
b- 如果为true,则绘制边框。 - 参见:
-
paintBorder
如果borderPainted属性为true,则绘制弹出菜单的边框。- 覆盖:
-
paintBorder在类JComponent中 - 参数:
-
g-Graphics对象 - 参见:
-
getMargin
返回弹出菜单的边框与其容器之间的像素间距。- 返回:
-
包含间距值的
Insets对象。
-
paramString
返回此JPopupMenu的字符串表示形式。此方法仅用于调试目的,返回的字符串的内容和格式可能因实现而异。返回的字符串可能为空,但不会是null。- 覆盖:
-
paramString在类JComponent中 - 返回:
-
此
JPopupMenu的字符串表示形式。
-
getAccessibleContext
获取与此JPopupMenu关联的AccessibleContext。对于JPopupMenus,AccessibleContext采用AccessibleJPopupMenu的形式。如有必要,将创建一个新的AccessibleJPopupMenu实例。- 指定:
-
getAccessibleContext在接口Accessible中 - 覆盖:
-
getAccessibleContext在类Component中 - 返回:
- 作为此JPopupMenu的AccessibleContext的AccessibleJPopupMenu
-
processMouseEvent
此方法需要符合MenuElement接口,但未实现。- 指定:
-
processMouseEvent在接口MenuElement中 - 参数:
-
event- 要处理的MouseEvent -
path- 菜单层次结构中接收元素的路径 -
manager- 菜单层次结构的MenuSelectionManager - 参见:
-
processKeyEvent
处理从MenuSelectionManager转发的键事件,并根据需要使用MenuSelectionManager的API更改菜单选择。注意:您无需将事件转发给子组件。这由
MenuSelectionManager自动完成。- 指定:
-
processKeyEvent在接口MenuElement中 - 参数:
-
e- 一个KeyEvent -
path-MenuElement路径数组 -
manager-MenuSelectionManager
-
getSubElements
返回包含此菜单组件子菜单的MenuElement数组。它将仅返回符合JMenuElement接口的项目。如果弹出菜单为null,则返回一个空数组。此方法需要符合MenuElement接口。- 指定由:
-
getSubElements在接口MenuElement - 返回:
-
一个
MenuElement对象数组 - 参见:
-
getComponent
返回此JPopupMenu组件。- 指定由:
-
getComponent在接口MenuElement - 返回:
-
此
JPopupMenu对象 - 参见:
-
isPopupTrigger
如果MouseEvent被JPopupMenu当前安装的UI视为弹出触发器,则返回true。- 参数:
-
e- 一个MouseEvent - 返回:
- 如果鼠标事件是弹出触发器,则返回true
- 自版本:
- 1.3
-
Container.getComponent(int)替代