How to create a Box Layout Frame in Core Java

In this tutorial how to create a Box Layout Frame in Core Java is shown.

Code:

BoxLayoutExample.java

import java.awt.*;
import javax.swing.*;

public class BoxLayoutExample extends Frame
{
Button buttons[];

public BoxLayoutExample()
{
buttons = new Button[5];

for(int i=0;i<5;i++)
{
buttons[i] = new Button(“Button” +(i+1));
add(buttons[i]);
}

setLayout(new BoxLayout(this,BoxLayout.X_AXIS));
setSize(400,400);
setVisible(true);
}

public static void main(String args[])
{
BoxLayoutExample b = new BoxLayoutExample();
}
}

Add a Comment

Your email address will not be published. Required fields are marked *