Using the GridBagLayout in AWT ~ foundjava
GridBagLayout is quite different and quite similar to FlowLayout, but with a difference in the position.
import java.awt.*;
class GridBagDemo extends Frame
{
Button b1;
Choice c1;
public GridBagDemo()
{
// Set the frame properties
setTitle("GridBagLayout Demo");
setSize(400,400);
setLayout(new GridBagLayout());
setLocationRelativeTo(null);
setVisible(true);
// Create button
b1=new Button(" Buy");
// Create choice
c1=new Choice();
// Add items
c1.add("Apple");
c1.add("Mango");
c1.add("Orange");
c1.add("Guava");
// Add choice
add(c1);
// Add button
add(b1);
}
public static void main(String args[])
{
new GridBagDemo();
}
}
GridBagDemo() : Code illustrating GridBagLayout is written herenew GridBagDemo() : Create the object for the class GridBagDemo
No comments:
Post a Comment