用户登录怎么弄
用box或Jpael怎么弄后面四个的//BoxLayout:箱式布局,一般水平或垂直方向堆叠组件使用,特别是标签和文本框的组合最为常见
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.*;
import
import
import
import
import
import
import javax.swing.*;
public class BoxLayOutDemo extends JFrame {
private JLabel userLabel;
private JTextField userField;
private JLabel passwordLabel;
private JLabel Confirmpassword;
private JPasswordField passwordField;
private JPasswordField ConfirmpasswordField;
private JButton login;
private JButton cancel;
private static String serverIP = "localhost";
private static int PORT = 8000;
private Socket socket;
private ObjectOutputStream out;
private ObjectInputStream in;
public BoxLayOutDemo() {
super("用户注册");
userLabel = new JLabel("用户名:");
userField = new JTextField(23);
passwordLabel = new JLabel("密 码 :");
passwordField = new JPasswordField(23);
Confirmpassword = new JLabel("确认密 码:");
ConfirmpasswordField = new JPasswordField(23);
login = new JButton("登录");
cancel = new JButton("取消");
Box box1 = new Box(BoxLayout.X_AXIS);
Box box2 = new Box(BoxLayout.X_AXIS);
Box box3 = new Box(BoxLayout.X_AXIS);
Box box5 = new Box(BoxLayout.X_AXIS);
box1.add(userLabel);
box1.add(userField);
box2.add(passwordLabel);
box2.add(passwordField);
box3.add(Confirmpassword);
box3.add(ConfirmpasswordField);
box5.add(login);
box5.add(cancel);
Box box = new Box(BoxLayout.Y_AXIS);
box.add(box1);
box.add(box2);
box.add(box3);
box.add(comboBox);
box.add(box5);
Container c = getContentPane();
c.add(box);
}
public static void main(String[] args) {
BoxLayOutDemo login = new BoxLayOutDemo();
BoxLayOutDemo cancel = new BoxLayOutDemo();
login.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
login.pack();
login.setVisible(true);
}
}