java - Getting String from Multi-Dimesnional -


could give me hand, please? have multi-dimensional array stores values of string.

private static jmenu[]                    menu_bars; private static final string[]             menu_names = {"file", "edit", "view", "search", "info"}; private static final string[][]           menu_item_data =                                             {{"new file","open   file", "close", "close all", "save", "saveas...", "print"},                                              {"undo typing", "redo", "cut", "copy", "paste", "delete", "select all"},                                               {"text color", "font", "text size", "background color"},                                              {"search..."},                                               {"spaces count", "words count", "sentences count"}}; 

so... multi-dimensional array contains arrays, how strings array contains.

and there's method there stuck.

//menucomponent private static void menucomponent(final jframe frame) {      bar = new jmenubar();     menu_bars = new jmenu[5];     int count = 0;      for(int i=0;i<5;i++) {         menu_bars[i] = new jmenu(menu_names[i]);       }      jmenuitem[] item = new jmenuitem[count = menu_item_data[0][1].length()];            for(int i=0;i<count;i++) {item[i] = new jmenuitem(menu_item_data[0][0] /*how pull strings array in argumments?*/ ); menu_bars[0].add(item[i]); }     jmenuitem[] item1 = new jmenuitem[count = menu_item_data[0][2].length()];            for(int i=0;i<count;i++) {item1[i] = new jmenuitem(menu_item_data[0][1]); menu_bars[1].add(item1[i]); }     jmenuitem[] item2 = new jmenuitem[count = menu_item_data[0][3].length()];            for(int i=0;i<count;i++) {item2[i] = new jmenuitem(menu_item_data[0][2]); menu_bars[2].add(item2[i]); }     jmenuitem[] item3 = new jmenuitem[count = menu_item_data[0][4].length()];            for(int i=0;i<count;i++) {item3[i] = new jmenuitem(menu_item_data[0][3]); menu_bars[3].add(item3[i]); }     jmenuitem[] item4 = new jmenuitem[count = menu_item_data[0][5].length()];            for(int i=0;i<count;i++) {item4[i] = new jmenuitem(menu_item_data[0][4]); menu_bars[4].add(item4[i]); }      for(int i=0;i<5;i++)         bar.add(menu_bars[i]);      frame.setjmenubar(bar);  } 

use nested loop.

final string[][] menu_item_data = {             { "new file", "open   file", "close", "close all", "save", "saveas...", "print" },             { "undo typing", "redo", "cut", "copy", "paste", "delete", "select all" },             { "text color", "font", "text size", "background color" }, { "search..." },             { "spaces count", "words count", "sentences count" } };  for(int = 0; < menu_item_data.length; ++i)         {             for(int j = 0; j < menu_item_data[i].length; ++j)             {                 system.out.println("["+ +"][" + j +"] " + menu_item_data[i][j]);             }         } output: [0][0] new file [0][1] open   file [0][2] close [0][3] close [0][4] save [0][5] saveas... [0][6] print [1][0] undo typing [1][1] redo [1][2] cut [1][3] copy [1][4] paste [1][5] delete [1][6] select [2][0] text color [2][1] font [2][2] text size [2][3] background color [3][0] search... [4][0] spaces count [4][1] words count [4][2] sentences count 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -