« Menu bar » : différence entre les versions
Aucun résumé des modifications |
Aucun résumé des modifications |
||
(4 versions intermédiaires par le même utilisateur non affichées) | |||
Ligne 1 : | Ligne 1 : | ||
As for a “classical” <font color=#FF8C00>GUI</font>, <font color=#556B2F> | As for a “classical” <font color=#FF8C00 title="Grahical User Interface>GUI</font>, <font color=#556B2F>'''GENIUS'''</font> proposes to have a main bar menu with the [{{PathCurrentJavaDoc}}/fr/cnes/genius/highLevel/GMenuBar.html GMenuBar] class (on the same principle as the swing <font color=#FF8C00>JMenuBar</font>). | ||
First, we will have to create a class that extends {{PathCurrentJavaDoc}}/fr/cnes/genius/lowLevel/GPanel.html GPanel] | First, we will have to create a class that extends [{{PathCurrentJavaDoc}}/fr/cnes/genius/lowLevel/GPanel.html GPanel] | ||
<syntaxhighlight lang="java"> | <syntaxhighlight lang="java"> | ||
Ligne 12 : | Ligne 12 : | ||
</syntaxhighlight> | </syntaxhighlight> | ||
In the constructor of this class, we will create the different items of the menu(s) using the [{{PathCurrentJavaDoc}}/fr/cnes/genius/highLevel/GMenuItem.html GMenuItem ] class. | In the constructor of this class, we will create the different items of the menu(s) using the [{{PathCurrentJavaDoc}}/fr/cnes/genius/highLevel/GMenuItem.html GMenuItem] class. | ||
<syntaxhighlight lang="java"> | <syntaxhighlight lang="java"> | ||
Ligne 35 : | Ligne 35 : | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Then, we will create the different menu(s) present in the [{{PathCurrentJavaDoc}}/fr/cnes/genius/highLevel/GMenuBar.html GMenuBar] using the [{{PathCurrentJavaDoc}}/fr/cnes/genius/highLevel/GMenu.html GMenu] class and associate items to this menu(s) using the <font color=#4169E1>add()</font> | Then, we will create the different menu(s) present in the [{{PathCurrentJavaDoc}}/fr/cnes/genius/highLevel/GMenuBar.html GMenuBar] using the [{{PathCurrentJavaDoc}}/fr/cnes/genius/highLevel/GMenu.html GMenu] class and associate items to this menu(s) using the <font color=#4169E1>add()</font> method. | ||
<syntaxhighlight lang="java"> | <syntaxhighlight lang="java"> | ||
Ligne 71 : | Ligne 71 : | ||
</syntaxhighlight> | </syntaxhighlight> | ||
We will initialize the menubar using the [{{PathCurrentJavaDoc}}/fr/cnes/genius/highLevel/GMenuBar.html GMenuBar] class, associate menu(s) to the menubar using the <font color=#4169E1>add()</font> | We will initialize the menubar using the [{{PathCurrentJavaDoc}}/fr/cnes/genius/highLevel/GMenuBar.html GMenuBar] class, associate menu(s) to the menubar using the <font color=#4169E1>add()</font> method and create a <font color=#4169E1>getMenuBar()</font> method that will return it. | ||
<syntaxhighlight lang="java"> | <syntaxhighlight lang="java"> | ||
Ligne 154 : | Ligne 154 : | ||
[[File: | [[File:MenuBarLevels.jpg]] | ||
[[WELCOME_TO_THE_GENIUS_WIKI|Return to the introduction ↑]] | [[WELCOME_TO_THE_GENIUS_WIKI|Return to the introduction ↑]] | ||
[[Icons|Go to the next page →]] | [[Icons|Go to the next page →]] |
Dernière version du 10 juillet 2017 à 07:57
As for a “classical” GUI, GENIUS proposes to have a main bar menu with the GMenuBar class (on the same principle as the swing JMenuBar).
First, we will have to create a class that extends GPanel
class myPanel extends GPanel {
myPanel () {
}
}
In the constructor of this class, we will create the different items of the menu(s) using the GMenuItem class.
class myPanel extends GPanel {
private GMenuItem itemLoad ;
private GMenuItem itemSave;
private GMenuItem itemQuit;
private GMenuItem itemHelp;
myPanel () {
// We create menu items
itemLoad = new GMenuItem("Load");
itemSave = new GMenuItem("Save");
itemQuit = new GMenuItem("Quit");
itemHelp = new GMenuItem("?");
}
}
Then, we will create the different menu(s) present in the GMenuBar using the GMenu class and associate items to this menu(s) using the add() method.
class myPanel extends GPanel {
private GMenuItem itemLoad ;
private GMenuItem itemSave;
private GMenuItem itemQuit;
private GMenuItem itemHelp;
private GMenu fileMenu;
private GMenu aboutMenu;
myPanel () {
// We create menu items
itemLoad = new GMenuItem("Load");
itemSave = new GMenuItem("Save");
itemQuit = new GMenuItem("Quit");
itemHelp = new GMenuItem("?");
// We create the “File” and the "About" menu containing the previous items
fileMenu= new GMenu("File");
aboutMenu= new GMenu("About");
// We link items to menus
fileMenu.add(itemLoad);
fileMenu.add(itemWrite);
fileMenu.add(itemQuit);
aboutMenu.add(itemHelp);
}
}
We will initialize the menubar using the GMenuBar class, associate menu(s) to the menubar using the add() method and create a getMenuBar() method that will return it.
class myPanel extends GPanel {
private GMenuItem itemLoad ;
private GMenuItem itemSave;
private GMenuItem itemQuit;
private GMenuItem itemHelp;
private GMenu fileMenu;
private GMenu aboutMenu;
private GMenuBar bar;
myPanel () {
// We create menu items
itemLoad = new GMenuItem("Load");
itemSave = new GMenuItem("Save");
itemQuit = new GMenuItem("Quit");
itemHelp = new GMenuItem("?");
// We create the “File” and the "About" menu containing the previous items
fileMenu= new GMenu("File");
aboutMenu= new GMenu("About");
// We link items to menus
fileMenu.add(itemLoad);
fileMenu.add(itemWrite);
fileMenu.add(itemQuit);
aboutMenu.add(itemHelp);
// Menu Bar initialization
bar = new GMenuBar(this);
bar.add(fileMenu);
bar.add(aboutMenu);
}
public GMenuBar getBar() { return bar; }
}
The GMenuBar will be associated to the main frame as this:
myPanel pan = new MyPanel();
GFrame frame = new GFrame("Test GChoice", pan, pan.getBar());
At last, we will check the action on this menu bar using the GListener interface:
public void after(GEvent e) throws Exception {
if (e.contains(itemQuit) ){
System.exit(0);
}
}
Note that since the V1.2 version, it is now possible to get several menu levels.
level1Menu = new GMenu("level 1");
itemLevel11 = new GMenuItem("level 1-1");
itemLevel12 = new GMenuItem("level 1-2");
level1Menu.add(itemLevel11);
level1Menu.add(itemLevel12);
// FileMenu initialization
level0Menu = new GMenu("Level 0");
level0Menu.add(level1Menu);