hi please help me with this code, i am new to Java and i have made this code using border layout but when i maximize my screen all components change there positions , how can i keep them in any desired position ?
import java.awt.*;
import javax.swing.*;
public class MyFrame
{
JLabel lbsex;
JTextField tf;
JButton bname;
JRadioButton rbmale;
JRadioButton rbfemale;
JLabel lbdob;
JLabel lbadd;
JTextArea tarea;
MyFrame()
{
JFrame frm=new JFrame();
frm.getContentPane().setLayout(new BorderLayout());
frm.setSize(300, 240);
bname=new JButton("Name");
Dimension dim=new Dimension(100, 25);
bname.setMinimumSize(dim);
tf=new JTextField(10);
Dimension dim1=new Dimension(400, 25);
tf.setMinimumSize(dim1);
tf.setMaximumSize(dim1);
Box b1=Box.createHorizontalBox();
Box b2=Box.createHorizontalBox();
b1.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
b2.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
b1.add(bname);
b1.add(Box.createRigidArea(new Dimension(0, 4)));
b1.createHorizontalGlue();
Dimension minSize = new Dimension(5, 100);
Dimension prefSize = new Dimension(5, 100);
Dimension maxSize = new Dimension(Short.MAX_VALUE, 100);
b1.add(new Box.Filler(minSize, prefSize, maxSize));
b1.add(tf);
lbsex=new JLabel("Sex");
rbmale=new JRadioButton("Male");
rbfemale=new JRadioButton("Female");
b2.add(lbsex);
b2.add(rbmale);
b2.add(Box.createRigidArea(new Dimension(0, 4)));
b2.add(rbfemale);
lbdob=new JLabel("Date Of Birth");
frm.getContentPane().add(b1, BorderLayout.NORTH);
frm.getContentPane().add(b2, BorderLayout.CENTER);
frm.pack();
frm.setVisible(true);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
}
public static void main (String args[])
{
//MyFrame mfrm=new MyFrame();
SwingUtilities.invokeLater(new Runnable(){ public void run(){ new MyFrame();}});
}
}