Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Help With Adding Buttons and assigning names

  Asked By: Bastet    Date: Feb 13    Category: Java    Views: 768
  

I have an array of buttons which i am adding to a container (16
buttons in all).

I am using a FOR loop to create/add the buttons. i am assigning the
value of the "counter" as the name of the buttons (0, 1, 2 etc...)
however when the counter reaches "10" i want to create the remaining
6 buttons with the names "A, B, C...F".

I have created a separate String array but i can only manage to
display the numbers and then the last 6 are all just "F" ???

heres my code:

String chars[] = {"A", "B", "C", "D", "E", "F"};

Button buttons[];

buttons = new Button[16];

for(int i = 0; i < 16; i++) {
buttons[i] = new Button("" + i);
//buttons[i].addActionListener(myHandler);
if(i >= 10) {
for(int j = 0; j < 6; j++) {
buttons[i] = new Button(chars[j]);
//buttons[i].addActionListener(myHandler);
}
}
superPanel.add(buttons[i]);
}

any help would be cool

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Help With Adding Buttons and assigning names Or get search suggestion and latest updates.




Tagged: