Wednesday, September 18, 2013

SWING PROGRAM TO GENERATE BUTTONS

PROGRAM:
~~~~~~~~~
import javax.swing.*;
import java.awt.*;
class exbutton extends JFrame
{
      Container  con;
     JButton b1;
     JPanel p1;
     e34()
{
    con=getContentPane();
   con.setLayout(new BorderLayout());
   p1=new JPanel();
    p1.setBackground(Color.RED);
   p1.setLayout(new GridLayout(3,3));
    for(int i=0;i<9;i++)       //generates button
{
b1=new JButton("click"+i);
                  p1.add(b1);
con.add("Center",p1);
}  
}

   public static void main(String args[]) throws Exception
{
exbutton obj=new exbutton();
     obj.setVisible(true);
    obj.setSize(400,400);
    obj.setTitle("this is my Frame");

}
}

OUTPUT:
~~~~~~~

No comments:

Post a Comment

Animated Social Gadget - Blogger And Wordpress Tips