I'm creating a Pac-man game in which I would like to use miglayout with a text file to set/get text out of cell. I have map (32x32) let's say. And I want to fill every cell with W
(ok that is not a problem, I can create a function which every time is called creates new JLable and add
it to the cell).
FUNCTION:
public void function(String rowColumn){
JLabel lblH = new JLabel("W");
contentPane.add(lblH, "cell " + rowColumn);
}
But then I can't read it.
Question: How do I read and write text in the cell?
EDIT: Or, is there any better layout which has cells and can set/get text from/to a cell?
The answer is this:
public static void start(){
for(int a = 0; a <= 22; a++){
for(int b = 0; b <= 37; b++){
printToCell(String.valueOf(b), String.valueOf(a), "H");
}
}
}
public static void clearContentPane(){
engine_design.Engine.contentPane.removeAll();
engine_design.Engine.contentPane.setLayout(new MigLayout("", "", ""));
}
public static void printToCell(String column, String row, String letter){
JLabel lblH = new JLabel(letter);
lblH.setFont(new Font(lblH.getName(), Font.BOLD, 15));
engine_design.Engine.contentPane.add(lblH, "cell " + column + " " + row);
}
And for the reading I will use list, how someones mentioned before.