界面建议用可视化来做,美观且便捷。下面这个是完全用代码写的,仅供参考。
创新互联服务项目包括平潭网站建设、平潭网站制作、平潭网页制作以及平潭网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,平潭网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到平潭省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;
public class Register extends JFrame {
JLabel jl1 = new JLabel("用户名");
JTextField jt1 = new JTextField();
JLabel jl2 = new JLabel("邮箱");
JTextField jt2 = new JTextField();
JLabel jl3 = new JLabel("密码");
JPasswordField jpw1 = new JPasswordField();
JLabel jl4 = new JLabel("密码确认");
JPasswordField jpw2 = new JPasswordField();
JButton register = new JButton("注册");
JButton clean = new JButton("清空");
public Register(){
setLayout(new GridLayout(5,2));
add(jl1);
add(jt1);
add(jl2);
add(jt2);
add(jl3);
add(jpw1);
add(jl4);
add(jpw2);
add(register);
add(clean);
String name = jt1.getText();
String email = jt2.getText();
String pw = jpw1.getText();
register.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/db","root","");
Statement sta = con.createStatement();
sta.executeUpdate("INSERT INTO register VALUES(name,email,pw)");
JOptionPane.showMessageDialog(null,"注册成功","提示",JOptionPane.INFORMATION_MESSAGE);
}
catch(Exception ex){
ex.getStackTrace();
}
}
});
clean.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
jt1.setText("");
jt2.setText("");
jpw1.setText("");
jpw2.setText("");
}
});
}
public static void main(String[] args){
Register frame = new Register();
frame.setTitle("用户注册");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,400);
frame.setVisible(true);
}
}
效果图
代码
!DOCTYPE html
html
head
meta charset="UTF-8"
title先锋图书馆管理系统-登录/title
style
*{
margin: 0;
padding: 0;
list-style: none;
}
#top{
width: 1000px;
height: 95px;
margin: 0 auto;
margin-top: 25px;
}
#top_top{
width: 1000px;
height: 65px;
background: deepskyblue;
}
#top_top_left{
width: 300px;
height: 65px;
float: left;
}
#top_top_leftlabel{
width: 200px;
height: 65px;
color: white;
float: right;
}
#top_top_left#a2{
padding-left: 10px;
padding-top: 20px;
font-size: 16px;
}
#top_bottom{
width: 1000px;
height: 30px;
}
#top_bottom_left{
width: 340px;
height: 30px;
line-height: 30px;
font-size: 12px;
background: skyblue;
color: white;
text-indent: 2em;
float: left;
}
#top_bottom_right{
width: 660px;
height: 30px;
line-height: 30px;
font-size: 12px;
color: blueviolet;
text-align: center;
float: right;
background: lightskyblue;
}
#content{
width: 1000px;
height: 600px;
margin: 0 auto;
background:#587FBA;
}
#content#text{
width: 1000px;
height: 50px;
line-height: 50px;
padding-top: 100px;
font-size: 36px;
font-family:"楷体";
font-weight: bold;
text-align: center;
}
#content#login{
width: 480px;
height: 210px;
margin-top: 20px;
margin-left: 260px;
background: #85A0CB;
}
#content#loginimg{
float: left;
}
#content#login#select{
width: 305px;
height: 210px;
float: right;
}
#content#login#selectdiv{
width: 230;
height: 30px;
margin-left: 30px;
}
#content#login#select#d1{
margin-top:30px;
margin-bottom: 3px;
}
#content#login#selectp{
font-size: 14px;
margin-left: 95px;
}
#bottom{
width: 1000px;
height: 35px;
line-height: 35px;
margin: 0 auto;
background: deepskyblue;
text-align: center;
color: white;
}
/style
/head
body
div id="top"
div id="top_top"
div id="top_top_left"
img src="img/test/a13.png" width="78px" height="65px"label id="a2"先锋图书馆系统管理平台/label
/div
/div
div id="top_bottom"
div id="top_bottom_left"当前位置 : 首页 系统管理 登录/div
div id="top_bottom_right"当前时间 : label id="lable"/label/div
/div
/div
div id="content"
div id="text"欢迎登录先锋图书馆管理系统/div
div id="login"
img src="img/test/a14.png" width="175px" height="210px"/
form id="select"
div id="d1"用户名: nbsp;nbsp;input type="text" //div
div密 nbsp; 码: nbsp;nbsp;input type="password" //div
p
input type="radio" name="user" value="read"/读者nbsp;nbsp;nbsp;nbsp;
input type="radio" name="user" value="admin"/管理员
/pbr/
p
input type="button" value="确定" style="width: 50px;" onclick="put()"/nbsp;nbsp;nbsp;nbsp;
input type="reset" value="重置" style="width: 50px;"/
/p
/form
/div
/div
div id="bottom"欣欣科技有限公司版权所有/div
/body
script type="text/javascript" src="JQuery/jquery.js"/script
script type="text/javascript" src="js/GetCurrentTime.js"/script
script
//验证用户名和密码
function put(){
var d = $("#selectdivinput");//获取用户名和密码
var name = d[0].value;
var pass = d[1].value;
var user = null;
var r = document.getElementsByName("user");//获取用户类型
for(i=0;ir.length;i++){
if(r[i].checked){
user=r[i].value;
}
}
//console.log(name + "," +pass + "," +user);//输出测试
if(user==null){
window.alert("请选择用户类型!");
}else if(user=="admin" name!="admin"){
window.alter("用户名错误!");
}else if(user=="admin" name=="admin" pass!="123456"){
window.alert("密码错误!");
}else if(name=="admin" pass=="123456" user=="admin"){
window.location.href="work_02_welcome.html";//在js中在本页面中打开新链接
}else{
window.alert("用户名错误");
}
}
/script
/html
java写的用户登录实例,实际页面展示使用的jsp,那么下面是jsp的登录页面代码:
1、login.jsp代码
%
string name = request.getparameter("username");
string pwd = request.getparameter("password");
//out.println(name+pwd);
string sql ="select * from info where username='"+name+"' and password='"+pwd+"'";
//out.println(sql);
statement stm= null;
resultset rs =null;
try
{
stm = conn.createstatement();
rs = stm.executequery(sql);
if(rs.next())
{
session.setattribute("username",name);
response.sendredirect("index.html");
}
else
{
response.sendredirect("index1.html");
}
}
catch(sqlexception e)
{
e.printstacktrace();
}
%
!--登录的表单--
form name="form1" method="post" action="login.jsp"
p
label for="username"/label 用户名
input type="text" name="username" id="username"
/p
p
label for="passwrod"/label 密码
input type="text" name="passwrod" id="passwrod"
/p
p
input type="submit" name="button" id="button" value="提交"
/p
/form
2、用户信息表,存放用户名和密码:
user_info 表
create table if not exists `test` (
`id` int(8) not null auto_increment,
`username` char(150) default null,
`password` varchar(32),
`times` int(4) not null,
primary key (`id`)
) engine=myisam default charset=utf8 auto_increment=1 ;
这篇文章主要介绍了java通过JFrame做一个登录系统的界面完整代码示例,具有一定借鉴价值,需要的朋友可以参考下。
在java的JFrame内通过创建匿名对象的方式做登录界面
package com.sxt;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class LoginFrame extends JFrame{
JTextField txtname=new JTextField();
JPasswordField txtpass=new JPasswordField();
JButton bl=new JButton("登录");
JButton bg=new JButton("关闭");
//构造无参构造器把主要的方法放在构造器里,然后在main方法里面调
public LoginFrame(){
setBounds(25,25,250,250);
Container c = getContentPane();
c.setLayout(new GridLayout(4,2,10,10));
c.add(new JLabel("用户名"));
c.add(txtname);
c.add(new JLabel("密码"));
c.add(txtpass);
c.add(bl);
c.add(bg);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
//注意:此处是匿名内部类
bg.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.exit(0);
}
}
);
//注意:此处是匿名内部类
bl.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {