Java注册界面设计.doc

上传人:xin****828 文档编号:6707888 上传时间:2020-03-02 格式:DOC 页数:5 大小:25.50KB
返回 下载 相关 举报
Java注册界面设计.doc_第1页
第1页 / 共5页
Java注册界面设计.doc_第2页
第2页 / 共5页
Java注册界面设计.doc_第3页
第3页 / 共5页
点击查看更多>>
资源描述
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 javax.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.JTextField;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 serialVersionUID = -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 RegisterPanel(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 JPasswordField 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) 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 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.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.addActionListener(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(cancelbtn);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);addCompnent(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.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 addCompnent(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(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(null, 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.showMessageDialog(null, t 年龄输入不合法);return;JOptionPane.showMessageDialog(null, t 注册成功! + n 姓名:+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;
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 图纸专区 > 中学资料


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!