Total members 11895 |It is currently Sun Dec 22, 2024 9:29 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





MenuBar,Menu,MenuItem,CheckboxMenuItem Example
java code
import java.awt.*;

public class MenuWindow extends Frame {
boolean startApplet = true;
TextArea output;

public MenuWindow() {
MenuBar menuBar;
Menu menuOne, menuTwo, menuThree, menuFour, menuFour_1, menuFive;
MenuItem menuItem_1, menuItem_2, menuItem3_1, menuItem3_2, menuItem3_3, menuItem3_4,
menuItem4_1_1, menuItem5_1, menuItem5_2;
CheckboxMenuItem checkBoxMenuItem_1;

output = new TextArea(5, 30);
output.setEditable(false);
setLayout(new BorderLayout()); //give max space to the output
add("Center", output);

//Build the menu bar.
menuBar = new MenuBar();
setMenuBar(menuBar);

//Build first menu in the menu bar.
//Specifying the second argument as true
//makes this a tear-off menu.
menuOne = new Menu("Menu 1", true);
menuBar.add(menuOne);
menuItem_1 = new MenuItem("Menu Item 1_1");
menuOne.add(menuItem_1);
menuItem_2 = new MenuItem("Menu Item 1_2");
menuOne.add(menuItem_2);

//Build help menu.
menuFive = new Menu("Menu 5");
menuBar.add(menuFive); //just setting the help menu doesn't work; must add it
menuBar.setHelpMenu(menuFive);
menuItem5_1 = new MenuItem("Menu Item 5_1");
menuFive.add(menuItem5_1);
menuItem5_2 = new MenuItem("Menu Item 5_2");
menuFive.add(menuItem5_2);

//Build second menu in the menu bar.
menuTwo = new Menu("Menu 2");
menuBar.add(menuTwo);
checkBoxMenuItem_1 = new CheckboxMenuItem("Menu Item 2_1");
menuTwo.add(checkBoxMenuItem_1);

//Build third menu in the menu bar.
menuThree = new Menu("Menu 3");
menuBar.add(menuThree);
menuItem3_1 = new MenuItem("Menu Item 3_1");
menuThree.add(menuItem3_1);
menuItem3_2 = new MenuItem("Menu Item 3_2");
menuThree.add(menuItem3_2);
menuThree.addSeparator();
menuItem3_3 = new MenuItem("Menu Item 3_3");
menuThree.add(menuItem3_3);
menuItem3_4 = new MenuItem("Menu Item 3_4");
menuItem3_4.disable();
menuThree.add(menuItem3_4);

//Build fourth menu in the menu bar.
menuFour = new Menu("Menu 4");
menuBar.add(menuFour);
menuFour_1 = new Menu("Submenu 4_1");
menuFour.add(menuFour_1);
menuItem4_1_1 = new MenuItem("Menu Item 4_1_1");
menuFour_1.add(menuItem4_1_1);
}

public boolean handleEvent(Event event) {
if (event.id == Event.WINDOW_DESTROY) {
if (startApplet) {
dispose();
} else {
System.exit(0);
}
}
return super.handleEvent(event);
}

public boolean action(Event event, Object arg) {
String str = "Action detected";

if (event.target instanceof MenuItem) {
MenuItem mi=(MenuItem)(event.target);
str += " on " + arg;
if (mi instanceof CheckboxMenuItem) {
str += " (state is "
+ ((CheckboxMenuItem)mi).getState()
+ ")";
}
MenuContainer parent = mi.getParent();
if (parent instanceof Menu) {
str += " in " + ((Menu)parent).getLabel();
} else {
str += " in a container that isn't a Menu";
}
}
str += ".\n";
output.appendText(str);
return true;
}

public static void main(String[] args) {
MenuWindow window = new MenuWindow();
window.startApplet = false;

window.setTitle("MenuWindow Application");
window.pack();
window.show();
}
}




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : MenuBar,Menu,MenuItem,CheckboxMenuItem Example
 difference between a MenuItem and a CheckboxMenuItem     -  
 How can i add a menu ?     -  
 usage of menu tag     -  
 Menu Style Button     -  
 Creating Menu Button     -  
 Skymiles v1.1 Menu buttons     -  
 navigation menu using JQuery     -  
 Javascript select menu validation issue     -  
 changing the background color for site main menu.     -  
 Show sidebar main menu with scroll down in the web page     -  



Topic Tags

Java AWT






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com