08 September 2010

How to create a array of buttons in java

Few days ago one of my friend named Mohit from Bihar faced a problem in java, in which he wants to create a array of button and change its size
So here is the code for creating a array of buttons in java

import java.applet.*;
import java.awt.*;
import javax.swing.*;
<applet CODE="kk.java" HEIGHT=300 WIDTH=400 > < /APPLET >
public class kk extends JApplet
{
JButton b[]=new JButton[20];
public void init ()
{
for(int i=0;i<20;i++)
{
setLayout(new FlowLayout());
b[i]=new JButton("click");
add(b[i]);
}
}
public void paint(Graphics g)
{
for(int j=0;j<20;j++)
{
b[j].setSize(4,90);
}
}
}




If you face any difficulty in understanding this code then post your query here

No comments:

Post a Comment