Extras din curs
Metode
add (MenuItem)
Adds the specified item to this menu.
add(String)
Adds an item with with the specified label to this menu.
addSeparator()
Adds a separator line, or a hypen, to the menu at the current position.
countItems()
Returns the number of elements in this menu.
getItem(int)
Returns the item located at the specified index of this menu.
isTearOff()
Returneaza true daca meniul este cu afisare permanenta.
remove(int)
Deletes the item from this menu at the specified index.
remove(MenuComponent)
Deletes the specified item from this menu.
Clasa MenuItem
Ofera optiunile individuale ale meniurilor derulante, cum sunt “Open”, “CLose”, “Exit”, etc. Este înrudita cu clasa CheckboxMenuItem, care permite comutari on/off pentru articolele de meniu.
Constructor
MenuItem (String nume)
Construieste un meniu având ca eticheta sirul nume
Metode
disable()
Makes this menu item unselectable by the user.
enable()
Makes this menu item selectable by the user.
enable(boolean)
Conditionally enables a component.
getLabel()
Gets the label for this menu item.
isEnabled()
Checks whether the menu item is enabled.
setLabel(String)
Sets the label to be the specified label.
Clasa CheckboxMenuItem
Are aceeasi functionalitate cu cea a casetelor de validare, dar se utilizeaza în cazul meniurilor. Extinde clasa MenuItem, adaugând metodele getState si setState.
Constructor
CheckboxMenuItem (String)
Creates the checkbox item with the specified label.
Metode
getState()
Returneaza starea articolului de meini (validat / invalidat)
setState(boolean)
Valideaza / Invalideaza articolul de meniu.
Exemplu - constuirea unui meniu
import java.awt.*;
import java.awt.event.*;
public class TestMenu1 {
public static void main(String argsst) {
Frame f = new Frame("Test Meniu");
MenuBar mb = new MenuBar();
Menu fisier = new Menu("File");
fisier.add(new MenuItem("Open"));
fisier.add(new MenuItem("Close"));
fisier.addSeparator();
fisier.add(new MenuItem("Exit"));
Menu optiuni = new Menu("Options");
optiuni.add(new MenuItem("Copy"));
optiuni.add(new MenuItem("Cut"));
optiuni.add(new MenuItem("Paste"));
Menu editare = new Menu("Edit");
editare.add(new MenuItem("Undo"));
editare.add(optiuni);
Menu stil = new Menu("Style");
stil.add(new CheckboxMenuItem("Bold"));
stil.add(new CheckboxMenuItem("Italic"));
mb.add(fisier);
mb.add(editare);
mb.add(stil);
f.setMenuBar(mb);
f.show();
}
}
Preview document
Conținut arhivă zip
- Meniuri in Java.doc