图形界面设计,布局方面有点问题,会的帮忙看下
import javax.swing.*;import java.awt.FlowLayout;
class MyFrame extends JFrame{
private JPanel contentPane;
private JLabel lab1,lab2,lab3;
private JTextField tf;
private JPasswordField pwf;
private JTextArea ta;
MyFrame (String s){
super(s);
setSize(300,300);
setLocationRelativeTo(null);
contentPane=new JPanel();
setContentPane(contentPane);
FlowLayout fLayout=new FlowLayout();
lab1=new JLabel("账号");
tf=new JTextField(15);
lab2=new JLabel("密码");
pwf=new JPasswordField(15);
lab3=new JLabel("发言");
ta=new JTextArea(10,15);
contentPane.add(lab1);
contentPane.add(tf);
contentPane.add(lab2);
contentPane.add(pwf);
contentPane.add(lab3);
contentPane.add(ta);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
}
public class TextFieldDemo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
MyFrame frm=new MyFrame("文本输入组件演示");
}
}
程序能运行,运行后结果杂乱排布着,就想,在不改变setsize()的大小的情况下,用布局的方法,使她对齐,该怎么改