Write a program that places some buttons in a specific manner using Layout manager.(File must be save as: SevenButtonPlacing.java)
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.Insets;
class Practice extends JFrame
{
GridBagLayout layout=new GridBagLayout();
GridBagConstraints c=new GridBagConstraints();
public Practice()
{
super("Buttons are placed as:");
setLayout(layout);
JButton button1=new JButton("Button1");
JButton button2=new JButton("Button2");
JButton button3=new JButton("Button3");
JButton button4=new JButton("Button4");
JButton button5=new JButton("Button5");
JButton button6=new JButton("Button6");
JButton button7=new JButton("Button7");
c.gridx=0;
c.gridy=0;
layout.setConstraints(button1,c);
add(button1);
c.gridx=2;
c.gridy=0;
layout.setConstraints(button2,c);
add(button2);
c.gridx=0;
c.gridy=1;
c.insets=new Insets(30,75,30,0);
layout.setConstraints(button3,c);
add(button3);
c.gridx=2;
c.gridy=1;
c.insets=new Insets(30,0,30,75);
layout.setConstraints(button4,c);
add(button4);
c.gridx=0;
c.gridy=2;
c.insets=new Insets(0,0,0,0);
layout.setConstraints(button5,c);
add(button5);
c.gridx=2;
c.gridy=2;
layout.setConstraints(button6,c);
add(button6);
c.gridx=1;
c.gridy=3;
c.insets=new Insets(20,0,0,0);
layout.setConstraints(button7,c);
add(button7);
}
}
public class Assignment13
{
public static void main(String args[])
{
Practice practice=new Practice();
practice.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
practice.setSize(400,300);
practice.setVisible(true);
}
}
////////////////////////////////////////////
Copy & paste this code in your Textpad & run, then you will get output.......
If you have any problem please comment below.........
Copy & paste this code in your Textpad & run, then you will get output.......
If you have any problem please comment below.........