本文整理汇总了Java中java.awt.MenuBar类的典型用法代码示例。如果您正苦于以下问题:Java MenuBar类的具体用法?Java MenuBar怎么用?Java MenuBar使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MenuBar类属于java.awt包,在下文中一共展示了MenuBar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addMenu
import java.awt.MenuBar; //导入依赖的package包/类
void addMenu(MenuBar b, String name, String[] items) {
/* It's a very poor design to encapsulate menu creation this way.
* Can't customize the menus this way (e.g. shortcut keys,
* mnemonics, disabling, etc. */
Menu menu = new Menu(name);
if (name.equals("Tools") && !TT_AVAILABLE) {
// Terrible place to do this. Forced to due to method design.
menu.setEnabled(false);
}
addMenuItems(menu, items);
b.add(menu);
}
示例2: addMenu
import java.awt.MenuBar; //导入依赖的package包/类
/**
* Method declaration
*
*
* @param b
* @param name
* @param items
*/
void addMenu(MenuBar b, String name, String[] items) {
/* It's a very poor design to encapsulate menu creation this way.
* Can't customize the menus this way (e.g. shortcut keys,
* mnemonics, disabling, etc. */
Menu menu = new Menu(name);
if (name.equals("Tools") && !TT_AVAILABLE) {
// Terrible place to do this. Forced to due to method design.
menu.setEnabled(false);
}
addMenuItems(menu, items);
b.add(menu);
}
示例3: createModel
import java.awt.MenuBar; //导入依赖的package包/类
@Override
long createModel() {
CMenuComponent parent = (CMenuComponent)
LWCToolkit.targetToPeer(getTarget().getParent());
if (parent instanceof CMenu) {
return parent.executeGet(this::nativeCreateSubMenu);
}
if (parent instanceof CMenuBar) {
MenuBar parentContainer = (MenuBar)getTarget().getParent();
boolean isHelpMenu = parentContainer.getHelpMenu() == getTarget();
int insertionLocation = ((CMenuBar)parent).getNextInsertionIndex();
return parent.executeGet(ptr -> nativeCreateMenu(ptr, isHelpMenu,
insertionLocation));
}
throw new InternalError("Parent must be CMenu or CMenuBar");
}
示例4: test3
import java.awt.MenuBar; //导入依赖的package包/类
private static void test3(final MenuBar menuBar) {
final Menu helpMenu1 = new Menu("Help Menu1");
final Menu helpMenu2 = new Menu("Help Menu2");
menuBar.setHelpMenu(helpMenu1);
checkCurrentMenu(menuBar, helpMenu1);
checkMenuCount(menuBar, 1);
checkHelpMenu(helpMenu1, true);
checkHelpMenu(helpMenu2, false);
menuBar.setHelpMenu(helpMenu2);
checkCurrentMenu(menuBar, helpMenu2);
checkMenuCount(menuBar, 1);
checkHelpMenu(helpMenu1, false);
checkHelpMenu(helpMenu2, true);
menuBar.remove(helpMenu2);
checkCurrentMenu(menuBar, null);
checkMenuCount(menuBar, 0);
checkHelpMenu(helpMenu1, false);
checkHelpMenu(helpMenu2, false);
}
示例5: addHelpMenu
import java.awt.MenuBar; //导入依赖的package包/类
/**
* Adds a help menu to this MenuBar. Gnome styleguides say the help
* menu is just the last item in the menubar (they are NOT right
* justified).
*/
public void addHelpMenu (Menu menu)
{
if (hasHelpMenu)
{
// Remove the (help) menu, which is after all the other items.
delMenu(((MenuBar) awtWidget).getMenuCount());
hasHelpMenu = false;
}
if (menu != null)
{
addMenu(menu);
hasHelpMenu = true;
}
}
示例6: setMenuBar
import java.awt.MenuBar; //导入依赖的package包/类
public void setMenuBar(MenuBar mb)
{
if( mb != null )
{
QtMenuBarPeer mbpeer = (QtMenuBarPeer)mb.getPeer();
if( mbpeer == null )
{
mb.addNotify();
mbpeer = (QtMenuBarPeer)mb.getPeer();
if( mbpeer == null )
throw new IllegalStateException("No menu bar peer.");
}
mbpeer.addMenus();
setMenu( mbpeer );
}
else
setMenu( null );
}
示例7: setMenuBar
import java.awt.MenuBar; //导入依赖的package包/类
public void setMenuBar(MenuBar mb)
{
if( mb != null )
{
QtMenuBarPeer mbpeer = (QtMenuBarPeer)mb.getPeer();
if( mbpeer == null )
{
mb.addNotify();
mbpeer = (QtMenuBarPeer)mb.getPeer();
if( mbpeer == null )
throw new IllegalStateException("No menu bar peer.");
}
mbpeer.addMenus();
setMenu( mbpeer );
}
else
setMenu( null );
}
示例8: OpenPartnerFrame
import java.awt.MenuBar; //导入依赖的package包/类
public OpenPartnerFrame (Go go)
{
super(Global.resourceString("Open_Partners"));
G = go;
MenuBar mb = new MenuBar();
setMenuBar(mb);
Menu m = new MyMenu(Global.resourceString("Options"));
m.add(new MenuItemAction(this, Global.resourceString("Close")));
mb.add(m);
setLayout(new BorderLayout());
L = new java.awt.List();
L.setFont(Global.SansSerif);
refresh();
add("Center", L);
JPanel bp = new MyPanel();
bp.add(new ButtonAction(this, Global.resourceString("Connect")));
bp.add(new ButtonAction(this, Global.resourceString("Refresh")));
bp.add(new MyLabel(" "));
bp.add(new ButtonAction(this, Global.resourceString("Close")));
add("South", bp);
Global.setwindow(this, "openpartner", 300, 200);
seticon("ijago.gif");
setVisible(true);
OPFU = new OpenPartnerFrameUpdate(this);
}
示例9: setMenuBar
import java.awt.MenuBar; //导入依赖的package包/类
public void setMenuBar(MenuBar mb) {
// state_lock should always be the second after awt_lock
XToolkit.awtLock();
try {
synchronized(getStateLock()) {
if (mb == menubar) return;
if (mb == null) {
if (menubar != null) {
menubarPeer.xSetVisible(false);
menubar = null;
menubarPeer.dispose();
menubarPeer = null;
}
} else {
menubar = mb;
menubarPeer = (XMenuBarPeer) mb.getPeer();
if (menubarPeer != null) {
menubarPeer.init((Frame)target);
}
}
}
} finally {
XToolkit.awtUnlock();
}
reshapeMenubarPeer();
}
示例10: main
import java.awt.MenuBar; //导入依赖的package包/类
/**
* Method declaration
*
*
* @param arg
*/
public static void main(String arg[]) {
fMain = new Frame("Query Tool");
QueryTool q = new QueryTool();
q.bApplication = true;
for (int i = 0; i < arg.length; i++) {
String p = arg[i];
if (p.equals("-?")) {
printHelp();
}
if (p.charAt(0) == '-') {
pProperties.put(p.substring(1), arg[i + 1]);
i++;
}
}
q.init();
q.start();
fMain.add("Center", q);
MenuBar menu = new MenuBar();
Menu file = new Menu("File");
file.add("Exit");
file.addActionListener(q);
menu.add(file);
fMain.setMenuBar(menu);
fMain.setSize(500, 400);
fMain.show();
fMain.addWindowListener(q);
}
示例11: main
import java.awt.MenuBar; //导入依赖的package包/类
/**
* Method declaration
*
*
* @param arg
*/
public static void main(String[] arg) {
fMain = new Frame("Query Tool");
QueryTool q = new QueryTool();
q.bApplication = true;
for (int i = 0; i < arg.length; i++) {
String p = arg[i];
if (p.equals("-?")) {
printHelp();
}
if (p.charAt(0) == '-') {
pProperties.put(p.substring(1), arg[i + 1]);
i++;
}
}
q.init();
q.start();
fMain.add("Center", q);
MenuBar menu = new MenuBar();
Menu file = new Menu("File");
file.add("Exit");
file.addActionListener(q);
menu.add(file);
fMain.setMenuBar(menu);
fMain.setSize(500, 400);
fMain.show();
fMain.addWindowListener(q);
}
示例12: test2
import java.awt.MenuBar; //导入依赖的package包/类
private static void test2(final MenuBar menuBar) {
final Menu helpMenu = new Menu("Help Menu");
menuBar.setHelpMenu(helpMenu);
checkCurrentMenu(menuBar, helpMenu);
checkMenuCount(menuBar, 1);
checkHelpMenu(helpMenu, true);
menuBar.remove(helpMenu);
checkCurrentMenu(menuBar, null);
checkMenuCount(menuBar, 0);
checkHelpMenu(helpMenu, false);
}
示例13: test4
import java.awt.MenuBar; //导入依赖的package包/类
private static void test4(final MenuBar menuBar) {
final Menu helpMenu = new Menu("Help Menu");
menuBar.setHelpMenu(helpMenu);
checkCurrentMenu(menuBar, helpMenu);
checkMenuCount(menuBar, 1);
checkHelpMenu(helpMenu, true);
menuBar.setHelpMenu(null);
checkCurrentMenu(menuBar, null);
checkMenuCount(menuBar, 0);
checkHelpMenu(helpMenu, false);
}
示例14: setMenuBar
import java.awt.MenuBar; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public void setMenuBar(MenuBar mb) {
// state_lock should always be the second after awt_lock
XToolkit.awtLock();
try {
synchronized(getStateLock()) {
if (mb == menubar) return;
if (mb == null) {
if (menubar != null) {
menubarPeer.xSetVisible(false);
menubar = null;
menubarPeer.dispose();
menubarPeer = null;
}
} else {
menubar = mb;
menubarPeer = AWTAccessor.getMenuComponentAccessor()
.getPeer(mb);
if (menubarPeer != null) {
menubarPeer.init((Frame)target);
}
}
}
} finally {
XToolkit.awtUnlock();
}
reshapeMenubarPeer();
}
示例15: ActionEventTest
import java.awt.MenuBar; //导入依赖的package包/类
public ActionEventTest() {
menuBar = new MenuBar();
Menu menu = new Menu("Menu1");
MenuItem menuItem = new MenuItem("MenuItem");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
System.out.println("actionPerformed");
int md = ae.getModifiers();
int expectedMask = ActionEvent.ALT_MASK | ActionEvent.CTRL_MASK
| ActionEvent.SHIFT_MASK;
isProgInterruption = true;
mainThread.interrupt();
if ((md & expectedMask) != expectedMask) {
throw new RuntimeException("Action Event modifiers are not"
+ " set correctly.");
}
}
});
menu.add(menuItem);
menuBar.add(menu);
setMenuBar(menuBar);
instructions = new TextArea(10, 50);
instructions.setText(
" This is a manual test\n" +
" Keep the Alt, Shift & Ctrl Keys pressed while doing next steps\n" +
" Click 'Menu1' Menu from the Menu Bar\n" +
" It will show 'MenuItem'\n" +
" Left mouse Click the 'MenuItem'\n" +
" Test exits automatically after mouse click.");
add(instructions);
setSize(400, 400);
setVisible(true);
validate();
}