FlowLayout Demo in Java AWT
As AWT stands for Abstract Window Toolkit, it is used for Windows Programming in Java (GUI). There are some classes those are used to arrange the controls in the form. FlowLayout is one of the Layout Class in Java. Below is the sample program that explains the FlowLayout.
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class FrameDemo2 extends Frame {
Button btnExit,btnOK;
TextField txt1,txt2;
public FrameDemo2()
{
btnExit=new Button("Exit");
btnOK= new Button("OK");
txt1= new TextField(10);
txt2 = new TextField(10);
setLayout(new FlowLayout(FlowLayout.CENTER));
add(txt1);
add(txt2);
add(btnOK);
add(btnExit);
btnExit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.exit(0);
}
});
setSize(200,300);
}
public static void main(String []a) {
FrameDemo2 d2= new FrameDemo2();
d2.setVisible(true);
}
}
In this program a Frame class is extended FlowLayout.LEFT in Floalayout constructor will arrange the controls from left side, default is FlowLayout.CENTER.
More Details can be founded at https://docs.oracle.com/javase/7/docs/api/java/awt/FlowLayout.html