import java.awt.Button;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.*;
public class Bag extends JFrame{
public Bag() {
GridBagConstraints g = new GridBagConstraints();
GridBagLayout l = new GridBagLayout();
this.setLayout(l);
g.fill = GridBagConstraints.HORIZONTAL;
g.gridx = 0;
g.gridy = 0;
this.add(new Button("Button One"), g);
g.gridx = 1;
g.gridy = 0;
this.add(new Button("Button two"), g);
g.gridx = 0;
g.gridy = 1;
this.add(new Button("Button Three"), g);
g.gridx = 1;
g.gridy = 1;
this.add(new Button("Button Four"), g);
g.gridx = 0;
g.gridy = 2;
g.gridwidth = 2;
this.add(new Button("Button Five"), g);
setSize(300, 300);
setVisible(true);
}
public static void main(String[] args) {
Bag a = new Bag();
}
}
OP:
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.*;
public class Bag extends JFrame{
public Bag() {
GridBagConstraints g = new GridBagConstraints();
GridBagLayout l = new GridBagLayout();
this.setLayout(l);
g.fill = GridBagConstraints.HORIZONTAL;
g.gridx = 0;
g.gridy = 0;
this.add(new Button("Button One"), g);
g.gridx = 1;
g.gridy = 0;
this.add(new Button("Button two"), g);
g.gridx = 0;
g.gridy = 1;
this.add(new Button("Button Three"), g);
g.gridx = 1;
g.gridy = 1;
this.add(new Button("Button Four"), g);
g.gridx = 0;
g.gridy = 2;
g.gridwidth = 2;
this.add(new Button("Button Five"), g);
setSize(300, 300);
setVisible(true);
}
public static void main(String[] args) {
Bag a = new Bag();
}
}
OP:
Comments
Post a Comment
If you have any query, please let us know