Thanks a lot charan. You code made me think.
The line
JButton[] b=new JButton[16];
was creating a new JButton array but not the objects at each position of the array. I guess I didn't understand it properly.
In side the loop i just created a new button and assigned it to each array position. The program compiles and works now. Thanks a lot buddy.
Code:
for (int i = 0; i < 16; i++) {
b[i]=new JButton(buttonText[i]);
buttonPanel.add(b[i]);
}
By the way I am just wondering. Not sure about the syntax of
VB.Net, but wouldn't this have been cleaner?
Code:
Private Sub MyBase_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim arrButtons(5) As Button
Dim iCount As Integer
For iCount = 1 To 5
set arrButtons(iCount)= New Button 'Create instance of new button
arrButtons(iCount).Name = "txtBox" & iCount.ToString 'Name button with sequential numbering
arrButtons(iCount).Width = 100
arrButtons(iCount).Text = "button" & iCount
arrButtons(iCount).Location = New Point(20, iCount * 25)
Me.Controls.Add(arrButtons(iCount)) 'Add new button to form
AddHandler arrButtons(iCount).Click, AddressOf ButtonClickEvent
offtopic: Oh, I have been like this since january. just didn't update my avatar. A guy at irc mentioned and I changed it now.
ah, chandru.in, I gained insight just as you were posting. Thanks a lot for confirming my idea.
SOLVED