Java注册界面设计.docx

上传人:罗晋 文档编号:11726514 上传时间:2021-09-01 格式:DOCX 页数:6 大小:68.54KB
返回 下载 相关 举报
Java注册界面设计.docx_第1页
第1页 / 共6页
Java注册界面设计.docx_第2页
第2页 / 共6页
Java注册界面设计.docx_第3页
第3页 / 共6页
Java注册界面设计.docx_第4页
第4页 / 共6页
Java注册界面设计.docx_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《Java注册界面设计.docx》由会员分享,可在线阅读,更多相关《Java注册界面设计.docx(6页珍藏版)》请在三一文库上搜索。

1、Java 注册界面设计package test;import java.awt.Component;import java.awt.Dimension;import java.awt.Font;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.BorderFactory;import jav

2、ax.swing.Box;import javax.swing.ButtonGroup;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JRadioButton;import javax.swing.JTextF

3、ield;import javax.swing.border.Border;import java.util.Vector;public class Register_GUI public Register_GUI() RegisterFrame rf = new RegisterFrame(); rf.setVisible(true);public static void main(String args) new Register_GUI();class RegisterFrame extends JFrame / 框架类/*/private static final long seria

4、lVersionUID = -3779096743730354383L;private Toolkit tool;public RegisterFrame() setTitle( 用户注册 );tool = Toolkit.getDefaultToolkit();Dimension ds = tool.getScreenSize();int w = ds.width;int h = ds.height;setBounds(w - 300) / 2, (h - 300) / 2, 300, 300); setResizable(false);RegisterPanel rp = new Regi

5、sterPanel(this);add(rp);class RegisterPanel extends JPanel implements ActionListener / 容器类 /*/private static final long serialVersionUID = -7078727217525013349L;private JLabel titlelabel, namelabel, pwdlabel1, pwdlabel2, sexlabel, agelabel, classlabel;private JTextField namefield, agefield;private J

6、PasswordField pwdfield1, pwdfield2;private JButton commitbtn, resetbtn, cancelbtn;private JRadioButton rbtn1, rbtn2;private JComboBox combo;private Vector v;private GridBagLayout gbl;private GridBagConstraints gbc;private JPanel panel;private Box box;private JFrame iframe;RegisterPanel(JFrame frame)

7、 iframe = frame;titlelabel = new JLabel( 用户注册 );titlelabel.setFont(new Font( 华文彩云 , Font.BOLD, 24);namelabel = new JLabel( 用 户 名: );pwdlabel1 = new JLabel( 密 码: );pwdlabel2 = new JLabel( 确认密码: );sexlabel = new JLabel( 性别:);agelabel = new JLabel( 年龄:);classlabel = new JLabel( 所属班级: );namefield = new

8、JTextField(16);pwdfield1 = new JPasswordField(16);pwdfield1.setEchoChar(*);pwdfield2 = new JPasswordField(16);pwdfield2.setEchoChar(*);agefield = new JTextField(16);rbtn1 = new JRadioButton( 男 );rbtn2 = new JRadioButton( 女);rbtn1.setSelected(true);ButtonGroup bg = new ButtonGroup();bg.add(rbtn1);bg.

9、add(rbtn2);v = new Vector();v.add(ACCP1);v.add(ACCP2);v.add(软件开发);v.add( 网络编程 );v.add(计算机应用);combo = new JComboBox(v);commitbtn = new JButton( 注册 );commitbtn.addActionListener(this);resetbtn = new JButton( 重置 );resetbtn.addActionListener(this);cancelbtn = new JButton( 取消 );cancelbtn.addActionListene

10、r(this);panel = new JPanel();panel.add(rbtn1);panel.add(rbtn2);Border border = BorderFactory.createTitledBorder(); panel.setBorder(border);box = Box.createHorizontalBox();box.add(commitbtn);box.add(Box.createHorizontalStrut(30); box.add(resetbtn);box.add(Box.createHorizontalStrut(30);box.add(cancelb

11、tn);gbl = new GridBagLayout();setLayout(gbl);gbc = new GridBagConstraints();addCompnent(titlelabel, 0, 0, 4, 1);add(Box.createVerticalStrut(20);gbc.anchor = GridBagConstraints.CENTER;gbc.fill = GridBagConstraints.HORIZONTAL;gbc.weightx = 0;gbc.weighty = 100;addCompnent(namelabel, 0, 1, 1, 1);addComp

12、nent(namefield, 1, 1, 4, 1);addCompnent(pwdlabel1, 0, 2, 1, 1);addCompnent(pwdfield1, 1, 2, 4, 1);addCompnent(pwdlabel2, 0, 3, 1, 1);addCompnent(pwdfield2, 1, 3, 4, 1);addCompnent(sexlabel, 0, 4, 1, 1);addCompnent(panel, 1, 4, 1, 1);gbc.anchor = GridBagConstraints.EAST;gbc.fill = GridBagConstraints.

13、NONE;addCompnent(agelabel, 2, 4, 1, 1);gbc.fill = GridBagConstraints.HORIZONTAL;addCompnent(agefield, 3, 4, 2, 1);addCompnent(classlabel, 0, 5, 4, 1);addCompnent(combo, 1, 5, 4, 1);gbc.anchor = GridBagConstraints.CENTER;gbc.fill = GridBagConstraints.NONE;addCompnent(box, 0, 6, 4, 1);public void addC

14、ompnent(Component c, int x, int y, int w, int h) gbc.gridx = x;gbc.gridy = y;gbc.gridwidth = w;gbc.gridheight = h;add(c, gbc);public void actionPerformed(ActionEvent e) Register rinfo = new Register();if (e.getSource() = commitbtn) rinfo.name = namefield.getText().trim();rinfo.password = new String(

15、pwdfield1.getPassword();rinfo.sex = rbtn1.isSelected() ? 男 : 女;rinfo.age = agefield.getText().trim();rinfo.nclass = combo.getSelectedItem().toString();if (rinfo.name.length() = 0) JOptionPane.showMessageDialog(null, t 用户名不能为空);return;if (rinfo.password.length() = 0) JOptionPane.showMessageDialog(nul

16、l, t 密码不能为空);return;if (!rinfo.password.equals(new String(pwdfield2.getPassword() JOptionPane.showMessageDialog(null, 密码两次输入不一致,请重新输入);return;if (rinfo.age.length() = 0) JOptionPane.showMessageDialog(null, t 年龄不能为空);return;int age = Integer.parseInt(rinfo.age); if (age 100) JOptionPane.showMessageDi

17、alog(null, t 年龄输入不合法);n 姓return; JOptionPane.showMessageDialog(null, t 注 册 成 功 !+名 :+rinfo.name+ n 性别 :+rinfo.sex+n 年龄 :+rinfo.age+n 班级 : +rinfo.nclass);if (e.getSource() = resetbtn) namefield.setText();pwdfield1.setText();pwdfield2.setText();rbtn1.isSelected();agefield.setText();combo.setSelectedIndex(0);if (e.getSource() = cancelbtn) iframe.dispose(); class Register String name;String password;String sex;String age;String nclass;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1