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:
~~~~~~~

SWING PROGRAM FOR PERSONAL DETAILS

PROGRAM:
~~~~~~~~~
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class a extends JFrame
{
JLabel l1,l2,l3,l4,l5;
JTextField t1,t2;
JCheckBox ch1,ch2;
JComboBox c;
List li;
JButton b1;
a()
{
l1=new JLabel("enter your name");
l2=new JLabel("enter your address");
l3=new JLabel("Hobby");
l4=new JLabel("Qualification");
l5=new JLabel("Nationality");
t1=new JTextField(20);
t2=new JTextField(20);
ch1=new JCheckBox("cricket");
ch2=new JCheckBox("football");
c=new JComboBox();
c.addItem("MCA");
c.addItem("BCA");
c.addItem("MTech");
c.addItem("Btech");
li=new List(1);
li.addItem("indian");
li.addItem("american");
li.addItem("japanese");
li.addItem("chinese");
b1=new JButton("submit");
setLayout(new FlowLayout());
add(l1);add(t1);
add(l2);add(t2);
add(l3);add(ch1);add(ch2);
add(l4);add(c);
add(l5);add(li);
add(b1);
}
public static void main(String h[])
{
a ob=new a();
ob.setSize(400,400);
ob.setTitle("MY FIRST FRAME");
ob.setVisible(true);
}
}

OUTPUT:
~~~~~~~


Animated Social Gadget - Blogger And Wordpress Tips