Results 1 to 4 of 4
- 12-11-2011, 07:32 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 20
- Rep Power
- 0
how to create many button with different name and variable with for loop?
This one i am really no idea how to make it...
Now i am using this:
but now i dont know how to add actionlistener to all the JButton...Java Code:for (int i = 0; i < line.length; i++) { Panel1.add(new JButton(sr)); }
I hope anyone can help me with it.
Thanks.
- 12-11-2011, 07:36 PM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Re: how to create many button with different name and variable with for loop?
Create an array of JButtons, then initialize them and add them to the panel in the for loop. You can also attach the actionlisteners in the loop -- or outside of it as well.
- 12-11-2011, 09:39 PM #3
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Re: how to create many button with different name and variable with for loop?
See my example is this posting: Basic Calculator
-
Re: how to create many button with different name and variable with for loop?
Or my example in this post: SimpleCalc.java
Similar Threads
-
Problem with while loop, assigning a variable with a different value every loop? Help
By JavaProg in forum New To JavaReplies: 2Last Post: 11-07-2011, 02:25 AM -
multiply variable in for loop
By aconti in forum New To JavaReplies: 7Last Post: 06-03-2011, 12:24 PM -
Accessing a variable from a loop
By mhz041986 in forum New To JavaReplies: 4Last Post: 04-04-2011, 08:49 AM -
Variable not initialized after while loop
By ejs7597 in forum New To JavaReplies: 6Last Post: 02-28-2009, 05:00 AM -
Create a new variable
By mathias in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:48 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks