Yumex85 wrote:
> Hello,
> Here it is a simple frame i made, with a menubar and several menus I
> added to menubar. Now I wanna add sub items to each menu. As you can
> see below, to add to menus, i made a loop, but now i dont know how i
> could add the sub items in each menu, coz i dont know the name of each
> object i created . do They all have "menu" name? Are they
> automatically kept in an array?
No, you should create your own structure for keeping track of them, this
could be an array but some other structure such as a hashmap keyed by
menu title might be more useful.
> String[] menuLista = { "Cadastros","Consultas","Relatórios",
> "Processamentos","Reconciliações","Logse Consistências",
> "Sobre","Sair"};
>
> public static void main(String[] args) {
>
> ABNAplic mainGui = new ABNAplic();
> mainGui.go();
It is normal to use a ABNAplic() constructor instead of your go() method.
> }
> public void go() {
ABNAplic() {
<snippage>
> for(String menus:menuLista) {
> JMenu menu = new JMenu(menus);
> menuBar.add(menu);
At this point you can add menu to an array or HashMap or other structure.
> }
|