1.
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class Test {
public static void main (String[] args){
// System.out.println("Hello,World!");
JFrame test= new JFrame();
test.setLayout(new FlowLayout(FlowLayout.CENTER,3,3));
JLabel userid = new JLabel("Useri8d");
JTextField user1 = new JTextField("user1",30);
JLabel passWord = new JLabel("password");
JPasswordField password = new JTextField("", 30);
JButton ok = new JButton("OK");
JButton cancel = new JButton("Cancel");
test.add(userid);
test.add(user1);
test.add(passWord);
test.add(password);
test.add(ok);
test.add(cancel);
test.setVisible(true);
test.pack();
}
}原文:http://anglecode.blog.51cto.com/5628271/1619869