时间:2021-05-19
本文实例为大家分享了swing登录注册界面展示的具体代码,供大家参考,具体内容如下
开发环境:Eclipse Neon.3 Release (4.6.3)
我用的为javaee版本的,为了便于设计界面,需要安装windowbuilder插件,可以直接在marketplace里搜索到。
说明:参考凯哥视频同步学习的
界面效果
登录界面
注册界面
关键技术
该项目用到了java swing外观插件
用到了图片(点击src右键文件夹取名res并复制图片login.jpg)
源码
com.lsh.view.LoginDialog
package com.lsh.view;import java.awt.BorderLayout;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JPanel;import javax.swing.border.EmptyBorder;import javax.swing.JTextField;import javax.swing.JLabel;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import javax.swing.ImageIcon;import javax.swing.border.TitledBorder;import com.lsh.util.ImageScale;@SuppressWarnings("serial")public class LoginDialog extends JDialog { private final JPanel contentPanel = new JPanel(); private JTextField textField; private JTextField textField_1; private JTextField textField_2; private JTextField textField_3; private JTextField textField_4; private JTextField textField_5; private static final int DIALOG_WIDTH=414; private static final int DIALOG_HEIGHT=340; private static final int DIALOG_HEIGHT_EXTEND=573; /** * Launch the application. */ public static void main(String[] args) { try { org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF(); } catch(Exception e) { //TODO exception System.out.println("加载炫彩皮肤失败!"); } try { LoginDialog dialog = new LoginDialog(); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } /** * Create the dialog. */ public LoginDialog() { setAlwaysOnTop(true); setResizable(false); setBounds(400, 100, DIALOG_WIDTH,DIALOG_HEIGHT); getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); contentPanel.setLayout(null); //设置居中 //setLocation(WindowXY.getXY(LoginDialog.this.getSize())); JButton btnNewButton = new JButton("注 册"); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if(LoginDialog.this.getHeight()==DIALOG_HEIGHT_EXTEND){ LoginDialog.this.setSize(DIALOG_WIDTH,DIALOG_HEIGHT); } else{ LoginDialog.this.setSize(DIALOG_WIDTH,DIALOG_HEIGHT_EXTEND); } } }); btnNewButton.setBounds(53, 224, 93, 23); contentPanel.add(btnNewButton); JButton btnNewButton_1 = new JButton("登 录"); btnNewButton_1.setBounds(190, 224, 93, 23); contentPanel.add(btnNewButton_1); textField = new JTextField(); textField.setBounds(133, 147, 150, 25); contentPanel.add(textField); textField.setColumns(10); textField_1 = new JTextField(); textField_1.setBounds(133, 182, 150, 25); contentPanel.add(textField_1); textField_1.setColumns(10); JLabel lblNewLabel = new JLabel("邮 箱"); lblNewLabel.setBounds(53, 151, 54, 15); contentPanel.add(lblNewLabel); JLabel lblNewLabel_1 = new JLabel("密 码"); lblNewLabel_1.setBounds(53, 194, 54, 15); contentPanel.add(lblNewLabel_1); JLabel lblNewLabel_2 = new JLabel("New label"); lblNewLabel_2.setBounds(0, 0, 360, 136); ImageIcon icon=new ImageIcon(LoginDialog.class.getResource("/res/login.jpg")); icon=ImageScale.getImage(icon, lblNewLabel_2.getWidth(), lblNewLabel_2.getHeight()); lblNewLabel_2.setIcon((icon)); contentPanel.add(lblNewLabel_2); JPanel panel = new JPanel(); panel.setBorder(new TitledBorder(null, "\u6CE8\u518C\u7528\u6237", TitledBorder.LEADING, TitledBorder.TOP, null, null)); panel.setBounds(12, 259, 336, 221); contentPanel.add(panel); panel.setLayout(null); JLabel lblNewLabel_3 = new JLabel("邮 箱"); lblNewLabel_3.setBounds(41, 29, 55, 18); panel.add(lblNewLabel_3); JLabel lblNewLabel_4 = new JLabel("验证码"); lblNewLabel_4.setBounds(41, 85, 55, 18); panel.add(lblNewLabel_4); JLabel lblNewLabel_5 = new JLabel("密 码"); lblNewLabel_5.setBounds(41, 115, 55, 18); panel.add(lblNewLabel_5); JLabel label = new JLabel("确认密码"); label.setBounds(41, 145, 55, 18); panel.add(label); textField_2 = new JTextField(); textField_2.setBounds(123, 22, 150, 25); panel.add(textField_2); textField_2.setColumns(10); textField_3 = new JTextField(); textField_3.setBounds(123, 80, 150, 25); panel.add(textField_3); textField_3.setColumns(10); textField_4 = new JTextField(); textField_4.setBounds(123, 113, 150, 25); panel.add(textField_4); textField_4.setColumns(10); textField_5 = new JTextField(); textField_5.setBounds(123, 145, 150, 25); panel.add(textField_5); textField_5.setColumns(10); JButton btnNewButton_2 = new JButton("发送验证码"); btnNewButton_2.setBounds(123, 52, 83, 23); panel.add(btnNewButton_2); JButton btnNewButton_3 = new JButton("取 消"); btnNewButton_3.setBounds(51, 182, 83, 27); panel.add(btnNewButton_3); JButton btnNewButton_4 = new JButton("确 认"); btnNewButton_4.setBounds(190, 182, 83, 27); panel.add(btnNewButton_4); }}工具类 com.lsh.util.ImageScale
package com.lsh.util;import java.awt.Image;import javax.swing.ImageIcon;public class ImageScale { public static ImageIcon getImage(ImageIcon icon,int width,int height){ Image image=icon.getImage().getScaledInstance(width, height,Image.SCALE_REPLICATE); icon.setImage(image); return icon; }}工具类 com.lsh.util.WindowXY
package com.lsh.util;import java.awt.Dimension;import java.awt.Point;import java.awt.Toolkit;public class WindowXY { public static Point getXY(int w,int h){ Toolkit toolkit=Toolkit.getDefaultToolkit(); int width=toolkit.getScreenSize().width; int height=toolkit.getScreenSize().height; return new Point((width-w)/2,(height-h)/2); } public static Point getXY(Dimension dimension) { return getXY(dimension.width, dimension.height); }}以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
通过对界面设计不同需求进行的分类以及界面设计元素对用户行为的影响,来研究用户在界面设计中所体现的重要性。交互性已经成为网络界面设计中设计追求的目标。为了使设计满
界面设计。网站界面是和用户产生最直接交流的部分,在界面设计中,要注意以下几点。第一,界面设计要在用户体验的基础上进行;第二,界面设计要考虑页面的形式和基本要素;
UIdesign即用户界面设计,用户界面设计是指软件的人机交互,操作逻辑,界面美观的整体设计。好的界面设计不仅让网页变得有个性有品位,还能让整个网站的操作变得简
用户的登录界面设计,当然其出发点就应该围绕用户体验来进行设计。用户体验如何把握,其实这很难描述,但是我们可以从网站建设细节出发,做好用户登录界面设置。一、尽可能
用户研究。用户指网站界面设计的服务对象。不同内容方向的网站界面设计针对不同的用户群体,了解这个群体需求的共性和个性是网站界面设计的前提。通过收集必要的信息来分析