java實現註冊介面設計
阿新 • • 發佈:2019-02-16
import java.awt.BorderLayout;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class MyFrame extends JFrame {
private JPanel pan1, pan2, pan3;
private JLabel labName, labPassword, labConfirm, labInstruction, labSex, labId, labNumber, labA;
private JTextField textField1, textField2;
private JPasswordField passwordField, passwordField2;
private JTextArea textArea;
private JRadioButton radioButton1, radioButton2;
private JComboBox comboBox;
private JCheckBox checkBox;
public MyFrame(String s) {
super(s);
setSize(320, 400);
setLocationRelativeTo(null);
JPanel contentPane = new JPanel(new BorderLayout());
setContentPane(contentPane);
pan1 = new JPanel();
contentPane.add(pan1, BorderLayout.NORTH);
labName = new JLabel("使用者名稱:");
textField1 = new JTextField(20);
labPassword = new JLabel("密碼:");
passwordField = new JPasswordField(20);
passwordField.setEchoChar('*');
labConfirm = new JLabel("確認密碼:");
passwordField2 = new JPasswordField(20);
passwordField2.setEchoChar('*');
pan1.add(labName);
pan1.add(textField1);
pan1.add(labPassword);
pan1.add(passwordField);
pan1.add(labConfirm);
pan1.add(passwordField2);
pan2 = new JPanel();
contentPane.add(pan2, BorderLayout.CENTER);
labInstruction = new JLabel("個人簡介:");
textArea = new JTextArea(10, 20);
labSex = new JLabel("性別:");
radioButton1 = new JRadioButton("男");
radioButton2 = new JRadioButton("女");
labId = new JLabel("證件型別:");
String[] item = { "身份證", "護照", "學生證", "駕駛證", "軍官證", "其他" };
comboBox = new JComboBox(item);
ButtonGroup btngroup = new ButtonGroup();
btngroup.add(radioButton1);
btngroup.add(radioButton2);
pan2.add(labInstruction);
pan2.add(textArea);
pan2.add(labSex);
pan2.add(radioButton1);
pan2.add(radioButton2);
pan2.add(labId);
pan2.add(comboBox);
pan3 = new JPanel();
contentPane.add(pan3, BorderLayout.SOUTH);
labNumber = new JLabel("證件號碼:");
textField2 = new JTextField(20);
labA = new JLabel("同意服務條款:");
checkBox = new JCheckBox("我已經看過並同意使用協議");
pan3.add(labNumber);
pan3.add(textField2);
pan3.add(labA);
pan3.add(checkBox);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
pack();
}
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class MyFrame extends JFrame {
private JPanel pan1, pan2, pan3;
private JLabel labName, labPassword, labConfirm, labInstruction, labSex, labId, labNumber, labA;
private JTextField textField1, textField2;
private JPasswordField passwordField, passwordField2;
private JTextArea textArea;
private JRadioButton radioButton1, radioButton2;
private JComboBox comboBox;
private JCheckBox checkBox;
public MyFrame(String s) {
super(s);
setSize(320, 400);
setLocationRelativeTo(null);
JPanel contentPane = new JPanel(new BorderLayout());
setContentPane(contentPane);
pan1 = new JPanel();
contentPane.add(pan1, BorderLayout.NORTH);
labName = new JLabel("使用者名稱:");
textField1 = new JTextField(20);
labPassword = new JLabel("密碼:");
passwordField = new JPasswordField(20);
passwordField.setEchoChar('*');
labConfirm = new JLabel("確認密碼:");
passwordField2 = new JPasswordField(20);
passwordField2.setEchoChar('*');
pan1.add(labName);
pan1.add(textField1);
pan1.add(labPassword);
pan1.add(passwordField);
pan1.add(labConfirm);
pan1.add(passwordField2);
pan2 = new JPanel();
contentPane.add(pan2, BorderLayout.CENTER);
labInstruction = new JLabel("個人簡介:");
textArea = new JTextArea(10, 20);
labSex = new JLabel("性別:");
radioButton1 = new JRadioButton("男");
radioButton2 = new JRadioButton("女");
labId = new JLabel("證件型別:");
String[] item = { "身份證", "護照", "學生證", "駕駛證", "軍官證", "其他" };
comboBox = new JComboBox(item);
ButtonGroup btngroup = new ButtonGroup();
btngroup.add(radioButton1);
btngroup.add(radioButton2);
pan2.add(labInstruction);
pan2.add(textArea);
pan2.add(labSex);
pan2.add(radioButton1);
pan2.add(radioButton2);
pan2.add(labId);
pan2.add(comboBox);
pan3 = new JPanel();
contentPane.add(pan3, BorderLayout.SOUTH);
labNumber = new JLabel("證件號碼:");
textField2 = new JTextField(20);
labA = new JLabel("同意服務條款:");
checkBox = new JCheckBox("我已經看過並同意使用協議");
pan3.add(labNumber);
pan3.add(textField2);
pan3.add(labA);
pan3.add(checkBox);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
pack();
}
}
public class MyFrameDemo {
public static void main(String[] args) {
MyFrame mf = new MyFrame("註冊介面");
}
}