欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

swing登录注册界面设计

程序员文章站 2023-12-13 09:45:16
本文实例为大家分享了swing登录注册界面展示的具体代码,供大家参考,具体内容如下 开发环境:eclipse neon.3 release (4.6.3) 我用的...

本文实例为大家分享了swing登录注册界面展示的具体代码,供大家参考,具体内容如下

开发环境:eclipse neon.3 release (4.6.3)

我用的为javaee版本的,为了便于设计界面,需要安装windowbuilder插件,可以直接在marketplace里搜索到。
说明:参考凯哥视频同步学习的

界面效果

登录界面

swing登录注册界面设计

注册界面

swing登录注册界面设计

关键技术

该项目用到了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);
  }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

上一篇:

下一篇: