Donald Tsang
Donald Tsang

Reputation: 3

How to effectively program my Java Swing?

I got some JLabel and wanted to setText:

private JLabel jlA1B1;
private JLabel jlA1B2;
private JLabel jlA1B3;

private JLable jlA2B1;
private JLable jlA2B2;
private JLable jlA2B3;

private JLable jlA3B1;
private JLable jlA3B2;
private JLable jlA3B3;

So the pattern is jlA[x]B[y]. Is it possible to create some sort of loop to program this pattern? For example:

for(int i=1; i<4; i++;){
    for(int j=1; j<4; j++;){
        jlA[i]B[j].setText(i);
    }
}

Sorry for my bad English

Upvotes: 0

Views: 50

Answers (1)

SteffenJacobs
SteffenJacobs

Reputation: 412

You could put your labels into a two-dimensional array and loop over the array.

Upvotes: 2

Related Questions