Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Populating panel with button using loop!  RSS feed

 
Dave Johnson
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to creat a panel that will have 7 buttons in it.
The labels of the buttons will be taken from a array of strings. The sensible solution would be to use a loop that would create these 7 buttons. I can't quite get my head around this problem any help would be most appreciated!
Thanks Dave.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which part is giving you problems? Is it working with an array, a loop, Buttons, a Panel... ?
What have you tried so far? What seems to not be working?
 
Dave Johnson
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is some code I'm playing with:

The loop doesn't seem to create the array of buttons with the labels stored in the choices array. It compiles but fails to show up in the applet.
The main body is here:

Another thing that I am attempting to acheive with this code is to make it an applet and an application. If you see I have commented out the main as it isn't quite right. I know this can be done but I am slightly wrong.
Please can you help???
Thanks, Dave.
 
Dave Johnson
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Managed the first bit:

It was array out of bounds. It is annoying trying to debug applets. This is why I want to make it both app & applet. The finished program can be used as an applet, but in the meantime in the prototype stage it would be far easier to work on it as an app.
 
Dave Johnson
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I managed the second bit aswell. For it to be an app & an applet I needed this code:

I was genuinely stuck but I wriggled and got loose some how!!
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done! I'm glad we could be your CardboardAnalyst.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!