javaweb漂亮的登录界面源码,html5登录界面源代码

http://www.itjxue.com  2023-01-20 12:27  来源:未知  点击次数: 

用java写一个登陆界面代码。

概述

具体框架使用jframe,文本框组件:JTextField;密码框组件:JPasswordField;标签组件:JLabel;复选框组件:JCheckBox;单选框组件:JRadioButton;按钮组件JButton。

登录界面:

代码实例

import javax.swing.*;

import java.awt.*; ? //导入必要的包

public class denglu extends JFrame{

JTextField jTextField ;//定义文本框组件

JPasswordField jPasswordField;//定义密码框组件

JLabel jLabel1,jLabel2;

JPanel jp1,jp2,jp3;

JButton jb1,jb2; //创建按钮

public denglu(){

jTextField = new JTextField(12);

jPasswordField = new JPasswordField(13);

jLabel1 = new JLabel("用户名");

jLabel2 = new JLabel("密码");

jb1 = new JButton("确认");

jb2 = new JButton("取消");

jp1 = new JPanel();

jp2 = new JPanel();

jp3 = new JPanel();

//设置布局

this.setLayout(new GridLayout(3,1));

jp1.add(jLabel1);

jp1.add(jTextField);//第一块面板添加用户名和文本框

jp2.add(jLabel2);

jp2.add(jPasswordField);//第二块面板添加密码和密码输入框

jp3.add(jb1);

jp3.add(jb2); //第三块面板添加确认和取消

// ? ? ? ?jp3.setLayout(new FlowLayout()); ?//因为JPanel默认布局方式为FlowLayout,所以可以注销这段代码.

this.add(jp1);

this.add(jp2);

this.add(jp3); ?//将三块面板添加到登陆框上面

//设置显示

this.setSize(300, 200);

//this.pack();

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setVisible(true);

this.setTitle("登陆");

}

public static void main(String[] args){

new denglu();

}

}

拓展内容

java swing包

Swing 是一个为Java设计的GUI工具包。

Swing是JAVA基础类的一部分。

Swing包括了图形用户界面(GUI)器件如:文本框,按钮,分隔窗格和表。

Swing提供许多比AWT更好的屏幕显示元素。它们用纯Java写成,所以同Java本身一样可以跨平台运行,这一点不像AWT。它们是JFC的一部分。它们支持可更换的面板和主题(各种操作系统默认的特有主题),然而不是真的使用原生平台提供的设备,而是仅仅在表面上模仿它们。这意味着你可以在任意平台上使用JAVA支持的任意面板。轻量级组件的缺点则是执行速度较慢,优点就是可以在所有平台上采用统一的行为。

概念解析:

JFrame?– java的GUI程序的基本思路是以JFrame为基础,它是屏幕上window的对象,能够最大化、最小化、关闭。

JPanel?– Java图形用户界面(GUI)工具包swing中的面板容器类,包含在javax.swing 包中,可以进行嵌套,功能是对窗体中具有相同逻辑功能的组件进行组合,是一种轻量级容器,可以加入到JFrame窗体中。。

JLabel?– JLabel 对象可以显示文本、图像或同时显示二者。可以通过设置垂直和水平对齐方式,指定标签显示区中标签内容在何处对齐。默认情况下,标签在其显示区内垂直居中对齐。默认情况下,只显示文本的标签是开始边对齐;而只显示图像的标签则水平居中对齐。

JTextField?–一个轻量级组件,它允许编辑单行文本。

JPasswordField?– 允许我们输入了一行字像输入框,但隐藏星号(*) 或点创建密码(密码)

JButton?– JButton 类的实例。用于创建按钮类似实例中的 "Login"。

JAVA Web 编写登陆界面?

%@ page language="java" import="java.util.*" pageEncoding="GBK"%

%

String path = request.getContextPath();

String basePath = request.getScheme() + "://"

+ request.getServerName() + ":" + request.getServerPort()

+ path + "/";

%

%@ taglib prefix="s" uri="/struts-tags"%

!-- fck编辑器引入--

%@ taglib uri="/FCKeditor" prefix="FCK"%

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

html

head

base href="%=basePath%"

titleMy JSP 'index.jsp' starting page/title

meta http-equiv="pragma" content="no-cache"

meta http-equiv="cache-control" content="no-cache"

meta http-equiv="expires" content="0"

meta http-equiv="keywords" content="keyword1,keyword2,keyword3"

meta http-equiv="description" content="This is my page"

!--

link rel="stylesheet" type="text/css" href="styles.css"

--

script language="javascript" src="%=path%/images/js/calendar.js"

/script

script type="text/javascript"

var getNow = new Date().getYear() + '-' + new Date().getMonth() + '-'

+ new Date().getDate();!--标题验证--

function testtitle(){

var title=document.getElementsByName("t_notice.title")[0].value;

var titleSpan=document.getElementById("titleSpan");

if(title.length==0){

titleSpan.innerHTML='公告标题不能为空';

titleSpan.style.color='red';

return false;

}else if(title.length=50){

titleSpan.innerHTML='公告标题长度不能超过50';

titleSpan.style.color='red';

return false;

}else{

titleSpan.innerHTML='正确';

titleSpan.style.color='green';

return true;

}

}

!-- 有效时间--

function DateDiff(sDate1, sDate2){ //sDate1和sDate2是2006-12-18格式 ,时间天数之差

var aDate, oDate1, oDate2, iDays ;

aDate = sDate1.split("-") ;

oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) ; //转换为12-18-2006格式

aDate = sDate2.split("-") ;

oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) ;

iDays = parseInt((oDate1 - oDate2) / 1000 / 60 / 60 /24) ; //把相差的毫秒数转换为天数

return iDays ;

}

function testbegindate(){//判断生效时间

var begindate=document.getElementsByName("t_notice.begindate")[0].value;

var begindateSpan=document.getElementById("begindateSpan");

var result=DateDiff(getNow,begindate)+30;

if(begindate.length==0){//生效时间未选

begindateSpan.innerHTML='生效时间不能为空';

begindateSpan.style.color='red';

return false;

}else{//生效时间有选

if(result0){//当前时间在选中的时间之后,这个生效时间可以

begindateSpan.innerHTML='生效时间不能小于当前时间';

begindateSpan.style.color='red';

return false;

}else{

begindateSpan.innerHTML='正确';

begindateSpan.style.color='green';

return true;

}

}

}

function testenddate(){//判断失效时间

var begindate=document.getElementsByName("t_notice.begindate")[0].value;

var begindateSpan=document.getElementById("begindateSpan");

var enddate=document.getElementsByName("t_notice.enddate")[0].value;

var enddateSpan=document.getElementById("enddateSpan");

if(begindate.length==0){//生效时间未选

begindateSpan.innerHTML='生效时间不能为空';

begindateSpan.style.color='red';

return false;

}else if(enddate.length==0){//失效时间未选

enddateSpan.innerHTML='失效时间不能为空';

enddateSpan.style.color='red';

return false;

}

var result=DateDiff(begindate,enddate);

if(result0){//生效时间在失效时间之后

enddateSpan.innerHTML='失效时间不能小于生效时间';

enddateSpan.style.color='red';

return false;

}else{

enddateSpan.innerHTML='正确';

enddateSpan.style.color='green';

return true;

}

}

//添加附件

var i=1;

function addMore(){

var buttonSpan=document.getElementById("buttonSpan");

if (i 3) {

buttonSpan.innerHTML='附件个数不能超过3个';

buttonSpan.style.color='red';

return false;

}

var td = document.getElementById("td");

var br = document.createElement("br");

var input = document.createElement("input");

var button = document.createElement("input");

input.name = "upload";

input.contentEditable="false";

input.type = "file";

button.type = "button";

button.value = "移除该附件" + i;

button.onclick = function() {

if (confirm("确定移除该文件吗?")) {

td.removeChild(br);

td.removeChild(input);

td.removeChild(button);

i--;

}

}

td.appendChild(br);

td.appendChild(input);

td.appendChild(button);

i++;

}

//公告内容判断

function testcontext(){

//var content=document.getElementsByName("t_notice.content")[0].value;

var content=document.getElementById("t_notice.content");

var contentSpan=document.getElementById("contentSpan");

if(content.length==0){

contentSpan.innerHTML='公告内容不能为空';

contentSpan.style.color='red';

return false;

}else{

contentSpan.innerHTML='正确';

contentSpan.style.color='green';

return true;

}

}

function testall(){

if(testtitle()testbegindate()testenddate()testcontext()){

alert('验证成功!');

return true;

}else{

alert('验证失败,请按要求完善公告相关信息');

return false;

}

}

/script

s:head /

/head

body

s:form action="notice!add" namespace="/dsd" method="post"

enctype="multipart/form-data" onsubmit="return testall();"

s:hidden name="t_notice.status" value="0"/s:hidden

table width="100%" height="100%"

tr bordercolor="blue"

td align="center" background="images/top_bg.gif" colspan="2"

公告发布

/td

/tr

tr

td align="center" width="50%"

公告标题:

/td

td

s:textfield name="t_notice.title" onblur="testtitle();"/s:textfield

span id="titleSpan"/span

/td

/tr

tr

td align="center" width="50%"

生效时间:

/td

td

s:textfield name="t_notice.begindate"

onfocus="show_cele_date(this,'','',this)"

onblur="testbegindate();"/s:textfield

span id="begindateSpan"/span

/td

/tr

tr

td align="center" width="50%"

失效时间:

/td

td

s:textfield name="t_notice.enddate"

onfocus="show_cele_date(this,'','',this)" onblur="testenddate();"/s:textfield

span id="enddateSpan"/span

/td

/tr

tr

td align="center" width="50%"

上传附件:

/td

td id="td"

input type="button" value="添加附件" onclick="addMore();" /

span id="buttonSpan"/span

/td

/tr

tr

td colspan="2" align="center"

!--s:hidden name="t_notice.content"/

--

FCK:editor id="t_notice.content" width="80%" height="320"

fontNames="宋体;黑体;隶书;楷体_GB2312;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana"

imageBrowserURL="/OA/FCKeditor/editor/filemanager/browser/default/browser.html?Type=ImageConnector=connectors/jsp/connector"

linkBrowserURL="/OA/FCKeditor/editor/filemanager/browser/default/browser.html?Connector=connectors/jsp/connector"

flashBrowserURL="/OA/FCKeditor/editor/filemanager/browser/default/browser.html?Type=FlashConnector=connectors/jsp/connector"

imageUploadURL="/OA/FCKeditor/editor/filemanager/upload/simpleuploader?Type=Image"

linkUploadURL="/OA/FCKeditor/editor/filemanager/upload/simpleuploader?Type=File"

flashUploadURL="/OA/FCKeditor/editor/filemanager/upload/simpleuploader?Type=Flash"

/FCK:editor

span id="contentSpan"/span

/td

/tr

tr

td align="center" colspan="2"

input type="button" value="返回" onclick="javascript:window.history.back();"/

s:submit value="添加" /

s:reset value="重置" /

/td

/tr

tr

td

s:fielderror /

/td

/tr

tr

td

s:actionerror /

/td

/tr

/table

/s:form

/body

/html

类似这样的 你好好研究下下吧

java 求一个好的登录界面

效果如图:

代码如下:

不懂的可以继续问我

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.ImageIcon;

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 entity.*;

import dao.*;

public class Login extends JFrame implements ActionListener {

userBean user=new userBean();

String name;

String password;

private JPanel jp = new JPanel();

private JLabel label=new JLabel();

private JLabel[] jlArr = { new JLabel("用户名:"), new JLabel("密码:"),new JLabel("") };

private JButton[] jbArr = { new JButton("登录"), new JButton("重置") };

private JTextField jt = new JTextField();

private JPasswordField pwd = new JPasswordField();

public Login() {

jp.setLayout(null);

for (int i = 0; i 2; i++) {

jlArr[i].setBounds(30, 20 + i * 50, 80, 26);

jbArr[i].setBounds(50 + i * 100, 130, 80, 26);

jp.add(jlArr[i]);

jp.add(jbArr[i]);

jbArr[i].addActionListener(this);

}

jt.setBounds(80, 20,180,30);

jp.add(jt);

jt.addActionListener(this);

? ? ? pwd.setBounds(80,70,180,30);

? ? ? jp.add(pwd);

? ? ? pwd.setEchoChar('*');

? ? ? pwd.addActionListener(this);

? ? ? jlArr[2].setBounds(10,180,300,30);

? ? ? jp.add(jlArr[2]);

? ? ? String url="1.png";

? ? ? label.setIcon(new ImageIcon(url));

? ? ? this.add(jp);

? ? ? this.setTitle("库存管理用户登录");

? ? ? this.setResizable(false);

? ? ? this.setBounds(100,100,300,250);

? ? ? this.setVisible(true);

}

?

@Override

public void actionPerformed(ActionEvent e){

if(e.getSource()==jt){

jt.requestFocus();

}else if(e.getSource()==jbArr[1]){

jlArr[2].setText("");

jt.setText("");

pwd.setText("");

jt.requestFocus();

}else{

name=jt.getText();

password=String.valueOf(pwd.getPassword());

user.setName(name);

user.setPassword(password);

try {

if(daofactory.getuserInstance().login(user)){//这里是我自己的查询数据库用户名和密码是否正确的方法

jlArr[2].setText("登录成功!");

}else{jlArr[2].setText("请输入正确的用户名和密码!");}

} catch (Exception e1) {

e1.printStackTrace();

}

}

}

public static void main(String[] args){

new Login();

}

}

求JAVA实现用户登录界面代码?

你要先学会截图哦,你发的看不清楚,重新写了一个你参考参考!

import java.awt.GridLayout;

import javax.swing.ButtonGroup;

import javax.swing.JButton;

import javax.swing.JComboBox;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JRadioButton;

import javax.swing.JTextField;

public class Day30A extends JFrame {

private static final long serialVersionUID = 1L;

private JLabel labelName,labelId,labelPass,labelMoney,labelSelect,labelCar;

private JComboBoxString jcb;

private JPanel jp1,jp2,jp3,jp4,jp5,jp6,jp7;

private ButtonGroup btg;

private JRadioButton jr1,jr2;

Day30A(){

this.setTitle("注册账户");

this.setLayout(new GridLayout(7,1));

this.setSize(300,280);

this.setLocationRelativeTo(null);

this.setDefaultCloseOperation(EXIT_ON_CLOSE);

init();

this.setVisible(true);

}

private void init() {

String str="卡片类型1,卡片类型2,卡片类型3,卡片类型4,卡片类型5";

jcb=new JComboBox(str.split(","));

labelId=new JLabel("账号: ");

labelName=new JLabel("姓名: ");

labelPass=new JLabel("密码: ");

labelMoney=new JLabel("开户金额:");

labelSelect=new JLabel("存款类型:");

labelCar=new JLabel("卡片类型:");

addFun1();

addFun2();

}

private void addFun2() {

this.add(jp1);

this.add(jp2);

this.add(jp3);

this.add(jp4);

this.add(jp5);

this.add(jp6);

this.add(jp7);

}

private void addFun1() {

jp1=new JPanel();

jp1.add(labelId);

jp1.add(new JTextField(15));

jp2=new JPanel();

jp2.add(labelName);

jp2.add(new JTextField(15));

jp3=new JPanel();

jp3.add(labelPass);

jp3.add(new JTextField(15));

jp4=new JPanel();

jp4.add(labelMoney);

jp4.add(new JTextField(13));

jp5=new JPanel();

jp5.add(labelSelect);

btg=new ButtonGroup();

jr1=new JRadioButton("定期");

jr2=new JRadioButton("活期",true);

btg.add(jr1);

btg.add(jr2);

jp5.add(jr1);

jp5.add(jr2);

jp6=new JPanel();

jp6.add(labelCar);

jp6.add(jcb);

jp7=new JPanel();

jp7.add(new JButton("确定"));

jp7.add(new JButton("取消"));

}

public static void main(String[] args) {

new Day30A();

}

}

jsp登陆界面源代码

1、login.jsp文件

%@ page language="java" contentType="text/html; charset=GB18030"

pageEncoding="GB18030"%

%@ page import="java.util.*" %

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

html

head

title登录页面/title

/head

body

form name="loginForm" method="post" action="judgeUser.jsp"

table

tr

td用户名:input type="text" name="userName" id="userName"/td

/tr

tr

td密码:input type="password" name="password" id="password"/td

/tr

tr

tdinput type="submit" value="登录" style="background-color:pink" input

type="reset" value="重置" style="background-color:red"/td

/tr

/table

/form

/body

/html

2、judge.jsp文件

%@ page language="java" contentType="text/html; charset=GB18030"

pageEncoding="GB18030"%

%@ page import="java.util.*" %

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

html

head

title身份验证/title

/head

body

%

request.setCharacterEncoding("GB18030");

String name = request.getParameter("userName");

String password = request.getParameter("password");

if(name.equals("abc") password.equals("123")) {

3、afterLogin.jsp文件

%

jsp:forward page="afterLogin.jsp"

jsp:param name="userName" value="%=name%"/

/jsp:forward

%

}

else {

%

jsp:forward page="login.jsp"/

%

}

%

/body

/html

%@ page language="java" contentType="text/html; charset=GB18030"

pageEncoding="GB18030"%

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

html

head

title登录成功/title

/head

body

%

request.setCharacterEncoding("GB18030");

String name = request.getParameter("userName");

out.println("欢迎你:" + name);

%

/body

/html

扩展资料:

java web登录界面源代码:

1、Data_uil.java文件

import java.sql.*;

public class Data_uil

{

public? Connection getConnection()

{

try{

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

}catch(ClassNotFoundException e)

{

e.printStackTrace();

}

String user="***";

String password="***";

String url="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=***";

Connection con=null;

try{

con=DriverManager.getConnection(url,user,password);

}catch(SQLException e)

{

e.printStackTrace();

}

return con;

}

public? String selectPassword(String username)

{

Connection connection=getConnection();

String sql="select *from login where username=?";

PreparedStatement preparedStatement=null;

ResultSet result=null;

String password=null;

try{

preparedStatement=connection.prepareStatement(sql);

preparedStatement.setString(1,username);

result=preparedStatement.executeQuery();//可执行的? ? ?查询

if(result.next())

password=result.getString("password");

}catch(SQLException e){

e.printStackTrace();

}finally

{

close(preparedStatement);

close(result);

close(connection);

}

System.out.println("找到的数据库密码为:"+password);

return password;?

}

public? void close (Connection con)

{

try{

if(con!=null)

{

con.close();

}

}catch(SQLException e)

{

e.printStackTrace();

}

}

public? void close (PreparedStatement preparedStatement)

{

try{

if(preparedStatement!=null)

{

preparedStatement.close();

}

}catch(SQLException e)

{

e.printStackTrace();

}

}

public? void close(ResultSet resultSet)

{

try{

if(resultSet!=null)

{

resultSet.close();

}

}catch(SQLException e)

{

e.printStackTrace();

}

}

}

2、login_check.jsp:文件

%@ page language="java" contentType="text/html; charset=utf-8"

pageEncoding="utf-8"%

!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ""

html

head

meta http-equiv="Content-Type" content="text/html; charset=utf-8"

title验证用户密码/title

/head

body

jsp:useBean id="util" class="util.Data_uil" scope="page" /

%

String username=(String)request.getParameter("username");

String password=(String)request.getParameter("password");

if(username==null||"".equals(username))

{

out.print("script language='javaScript' alert('用户名不能为空');/script");

response.setHeader("refresh", "0;url=user_login.jsp");

}

else

{

System.out.println("输入的用户名:"+username);

String passwordInDataBase=util.selectPassword(username);

System.out.println("密码:"+passwordInDataBase);

if(passwordInDataBase==null||"".equals(passwordInDataBase))

{

out.print("script language='javaScript' alert('用户名不存在');/script");

response.setHeader("refresh", "0;url=user_login.jsp");

}

else if(passwordInDataBase.equals(password))

{

out.print("script language='javaScript' alert('登录成功');/script");

response.setHeader("refresh", "0;url=loginSucces.jsp");

}

else

{

out.print("script language='javaScript' alert('密码错误');/script");

response.setHeader("refresh", "0;url=user_login.jsp");

}

}

%

/body

/html

3、loginSucces.jsp文件

%@ page language="java" contentType="text/html; charset=utf-8"

pageEncoding="utf-8"%

!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ""

html

head

meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"

titleInsert title here/title

/head

body

hr size="10" width="26%" align="left" color="green"

font size="6" color="red" 登录成功 /font

hr size="10" width="26%" align="left" color="green"

/body

/html

4、user_login.jsp文件

%@ page language="java" contentType="text/html; charset=utf-8"

pageEncoding="utf-8"%

!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ""

html

head

meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"

title登录界面/title

/head

body? background="C:\Users\win8\workspace\Login\image\9dcbdc339e72a5663b5c289fb5573c13_10.jpg"

center

brbrbrbrbrbr

h1 style="color:yellow"Login/h1

br

form name="loginForm" action="login_check.jsp" method="post"?

table Border="0"

tr

td账号/td

tdinput type="text" name="username"/td

/tr

tr

td密码/td

tdinput type="password" name="password"

/td

/tr

/table

br

input type="submit" value="登录" style="color:#BC8F8F"

/form

/center

/body

/html

JAVA 中 GUI登录界面设计源代码?

import java.awt.BorderLayout;

import java.awt.Container;

import java.awt.FlowLayout;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JPasswordField;

import javax.swing.JTextField;

public class Login {

private JFrame frame = new JFrame("登录");

private Container c = frame.getContentPane();

private JTextField username = new JTextField();

private JPasswordField password = new JPasswordField();

private JButton ok = new JButton("确定");

private JButton cancel = new JButton("取消");

public Login(){

frame.setSize(300,200);

c.setLayout(new BorderLayout());

initFrame();

frame.setVisible(true);

}

private void initFrame() {

//顶部

JPanel titlePanel = new JPanel();

titlePanel.setLayout(new FlowLayout());

titlePanel.add(new JLabel("系统管理员登录"));

c.add(titlePanel,"North");

//中部表单

JPanel fieldPanel = new JPanel();

fieldPanel.setLayout(null);

JLabel l1 = new JLabel("用户名:");

l1.setBounds(50, 20, 50, 20);

JLabel l2 = new JLabel("密 码:");

l2.setBounds(50, 60, 50, 20);

fieldPanel.add(l1);

fieldPanel.add(l2);

username.setBounds(110,20,120,20);

password.setBounds(110,60,120,20);

fieldPanel.add(username);

fieldPanel.add(password);

c.add(fieldPanel,"Center");

//底部按钮

JPanel buttonPanel = new JPanel();

buttonPanel.setLayout(new FlowLayout());

buttonPanel.add(ok);

buttonPanel.add(cancel);

c.add(buttonPanel,"South");

}

public static void main(String[] args){

new Login();

}

}

(责任编辑:IT教学网)

更多