Pages

Monday, January 30, 2017

Java Program based on layout manager

Hello Friends,Today we learn advance java program.Today I am taking an example of how to create container and create components like label,textbox and button and set their layout.

Java program based on layout manager example
import java.awt.*;
import javax.swing.*;
public class example extends JFrame
{
JTextField t1;
    JButton b1;
JLabel l1;
  
public example() throws Exception
    {
//creating container
      Container c=this.getContentPane();
c.setLayout(null);

                //creating textfield and set their layout
t1=new JTextField();
t1.setBounds(200,100,130,20);

                 //creating label and set their layout
l1= new JLabel("what is your name");
l1.setBounds(50,100,250,30);

                 //creating button and set their layout
    b1=new JButton("Save");
b1.setBounds(70,200,120,42);


c.add(t1);
c.add(l1);
c.add(b1);
    }
      
public  static void main(String args[]) throws Exception
{
example obj=new example();
obj.setTitle("Layout example");
obj.setSize(500,300);
obj.setLocationRelativeTo(null);
obj.setVisible(true);
obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}//End of main
}

OUTPUT


No comments:

Post a Comment