登录 之 GUI层

来源:互联网 发布:淘宝打折工具哪个好 编辑:程序博客网 时间:2024/05/22 00:24

接上文:

在上一篇说明中,做了一次形式上的开发需求分析;

本篇及后续篇章将把实现部分展现,上篇的最后部分展现的是与用户交互的GUI,本篇以此开始。

正文:

一个程序的好坏在不同的角色的人心中评判标准有所区别,但既然是与用户交互的,那么就以用户角色审视实现。

作为一个自然人,用户的角色天然就具备,因此在我看来,页面简单,整洁,布局合理是基本要求。

 

package com.net.ui;import java.awt.Color;import java.awt.Dimension;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;import com.net.convert.MakeCertPic;public class LandWindow {private JTextField userName;private JButton jb_submit;private JButton jb_cancle;private JButton jb_register;private JPasswordField passwd;private JLabel hintStr;private JLabel label_name_str;private JLabel label_pswd_str;private JTextField certText;private JLabel certPic;private MakeCertPic mcp = new MakeCertPic();private final int JTEXTWIDTH=100;private final int JHEIGHT=30;private final int JLABELWIDTH=100;private final int JBUTTONWIDTH=90;public LandWindow(){JFrame jf = new JFrame();jf.setTitle("XXX 登陆系统");jf.setPreferredSize(new Dimension(350, 250));JPanel jp = new JPanel();jp.setPreferredSize(new Dimension(350, 250));jp.setBackground(Color.lightGray);jf.setContentPane(jp);JLabel label_name = new JLabel();label_name.setPreferredSize(new Dimension(JLABELWIDTH, JHEIGHT));label_name.setText("登录名:");userName = new JTextField();userName.setPreferredSize(new Dimension(JTEXTWIDTH, JHEIGHT));label_name_str = new JLabel();label_name_str.setPreferredSize(new Dimension(JLABELWIDTH, JHEIGHT));label_name_str.setText(null);label_name_str.setForeground(Color.RED);jp.add(label_name);jp.add(userName);jp.add(label_name_str);JLabel label_pswd = new JLabel();label_pswd.setPreferredSize(new Dimension(JLABELWIDTH, JHEIGHT));label_pswd.setText("密    码:");passwd = new JPasswordField();passwd.setPreferredSize(new Dimension(JTEXTWIDTH, JHEIGHT));label_pswd_str = new JLabel();label_pswd_str.setPreferredSize(new Dimension(JLABELWIDTH, JHEIGHT));label_pswd_str.setText(null);label_pswd_str.setForeground(Color.RED);jp.add(label_pswd);jp.add(passwd);jp.add(label_pswd_str);JLabel labelPicTip = new JLabel();labelPicTip.setPreferredSize(new Dimension(JLABELWIDTH, JHEIGHT));labelPicTip.setText("校验码:");certText = new JTextField();certText.setPreferredSize(new Dimension(JTEXTWIDTH, JHEIGHT));certPic = new JLabel();passwd.setPreferredSize(new Dimension(JLABELWIDTH, JHEIGHT));jp.add(labelPicTip);jp.add(certText);jp.add(certPic);jb_submit = new JButton();jb_submit.setPreferredSize(new Dimension(JBUTTONWIDTH, JHEIGHT));jb_submit.setText("登 录");jb_cancle = new JButton();jb_cancle.setPreferredSize(new Dimension(JBUTTONWIDTH, JHEIGHT));jb_cancle.setText("重 置");jb_register = new JButton();jb_register.setPreferredSize(new Dimension(JBUTTONWIDTH, JHEIGHT));jb_register.setText("注册");hintStr = new JLabel();hintStr.setPreferredSize(new Dimension(300, JHEIGHT));hintStr.setText(null);hintStr.setForeground(Color.RED);jp.add(jb_submit);jp.add(jb_cancle);jp.add(jb_register);jp.add(hintStr);jf.pack();jf.setVisible(true);jf.setLocation(450, 300);jf.setResizable(false);jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}public JButton getSubmitButton(){return this.jb_submit;}public JButton getRegisterButton(){return this.jb_register;}public JButton getCancleButton(){return this.jb_cancle;}public JTextField getUserNameField(){return this.userName;}public JPasswordField getPasswdField(){return this.passwd;}public JLabel getStatLabel(){return this.hintStr;}public JLabel getUserNameLabel(){return this.label_name_str;}public JLabel getPasswdLabel(){return this.label_pswd_str;}public JTextField getCertTextField(){return this.certText;}public JLabel getCertPicLabel(){return this.certPic;}public String getCertPicStrValue(){return this.mcp.getCertPicStr();}public void refreshCertPicLabel(){this.certPic.setIcon(this.mcp.getCertPic());}}


 

以上代码运行的结果与实际的贴图存在部分出入,因为缺少验证码的自动生成,但是基本结构就是这样,敬请期待验证码的部分。

未完待续。。。

原创粉丝点击