Salve ragazzi è giusto fare:
vorrei capire meglio come gestire le azioni da associare ad ogni singola sezione del menu.codice:... JMenuBar menu = new JMenuBar(); JMenu[] section = new JMenu[2]; String sections[] = new String[] { "File", "Help" }; for (int i = 0; i < sections.length; i++ ) { section[i] = new JMenu( sections[i] ); final int p = i; ActionListener boardListener = new ActionListener (){ public void actionPerformed(ActionEvent e){ someMethod( p ); } }; section[i].addActionListener( boardListener ); menu.add( section[i] ); } ... private void someMethod( int i ) { ... }
Grazie anticipatamente.