用Java编写注册登录程序
什么都不说了 直接给你代码吧
作为一家“创意+整合+营销”的成都网站建设机构,我们在业内良好的客户口碑。创新互联提供从前期的网站品牌分析策划、网站设计、成都网站建设、成都网站设计、创意表现、网页制作、系统开发以及后续网站营销运营等一系列服务,帮助企业打造创新的互联网品牌经营模式与有效的网络营销方法,创造更大的价值。
package com.moliying.ui;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.List;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
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);
frame.setBounds(450, 300, 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 a1 = new JLabel("用户名:");
a1.setBounds(50, 20, 50, 20);
JLabel a2 = new JLabel("密 码:");
a2.setBounds(50, 60, 50, 20);
fieldPanel.add(a1);
fieldPanel.add(a2);
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");
ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println(username.getText().toString());
}
});
cancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.setVisible(false);
}
});
}
public static void main(String[] args) {
// new Login();
String ss = "abbabbbaabbbccba";
System.out.println(ss.split("b").length);
}
}
java编写一个用户注册及登录界面
mport java.awt.HeadlessException;
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.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
@SuppressWarnings("serial")
public class MainFrame extends JFrame {
JLabel lbl1 = new JLabel("用户名:");
JLabel lbl2 = new JLabel("密 码:");
JTextField txt = new JTextField("admin",20);
JPasswordField pwd = new JPasswordField(20);
JButton btn = new JButton("登录");
JPanel pnl = new JPanel();
private int error = 0;
public MainFrame(String title) throws HeadlessException {
super(title);
init();
}
private void init() {
this.setResizable(false);
pwd.setEchoChar('*');
pnl.add(lbl1);
pnl.add(txt);
pnl.add(lbl2);
pnl.add(pwd);
pnl.add(btn);
this.getContentPane().add(pnl);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if ("admin".equals(new String(pwd.getPassword()))){
pnl.removeAll();
JLabel lbl3 = new JLabel();
ImageIcon icon = new ImageIcon(this.getClass().getResource("pic.jpg"));
lbl3.setIcon(icon);
pnl.add(lbl3);
}
else{
if(error 3){
JOptionPane.showMessageDialog(null,"密码输入错误,请再试一次");
error++;
}
else{
JOptionPane.showMessageDialog(null,"对不起,您不是合法用户");
txt.setEnabled(false);
pwd.setEnabled(false);
btn.setEnabled(false);
}
}
}
});
}
public static void main(String[] args) {
MainFrame frm = new MainFrame("测试");
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setBounds(100, 100, 300, 120);
frm.setVisible(true);
}
}
用JAVA编写一个用户或注册登录界面。请哪位高手能够写下具体的代码,谢谢
效果图
代码
!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编程实现用户注册并进行登录操作
String username = "",password = "",passwordagain = ""; // 定义用户名和密码
将该变量等于为全局变量 或局部变量即可
java编写一个登陆和注册信息的源代码,最简单的就可以,不需要数据库的那种
你这个不用数据库真的是有点难搞
我写了个用集合存储的,你看看,能否帮上你
java.util.ListString list = new ArrayListString();
list.add("qq=123");//存储的时候用(用户名=密码)的形式
list.add("ww=456");
String username = "qq";
String password = "123";
for (int i = 0; i list.size(); i++) {
String num = username +"="+password;
if(num.equals(list.get(i))){
System.out.println("登录成功");
break;
}
}
java语言实现用户注册和登录
//这个是我写的,里面有连接数据库的部分。你可以拿去参考一下
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
class LoginFrm extends JFrame implements ActionListener// throws Exception
{
JLabel lbl1 = new JLabel("用户名:");
JLabel lbl2 = new JLabel("密码:");
JTextField txt = new JTextField(5);
JPasswordField pf = new JPasswordField();
JButton btn1 = new JButton("确定");
JButton btn2 = new JButton("取消");
public LoginFrm() {
this.setTitle("登陆");
JPanel jp = (JPanel) this.getContentPane();
jp.setLayout(new GridLayout(3, 2, 5, 5));
jp.add(lbl1);
jp.add(txt);
jp.add(lbl2);
jp.add(pf);
jp.add(btn1);
jp.add(btn2);
btn1.addActionListener(this);
btn2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == btn1) {
try {
Class.forName("com.mysql.jdbc.Driver");// mysql数据库
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost/Car_zl", "root", "1");// 数据库名为Car_zl,密码为1
System.out.println("com : "+ con);
Statement cmd = con.createStatement();
String sql = "select * from user where User_ID='"
+ txt.getText() + "' and User_ps='"
+ pf.getText() + "'" ;
ResultSet rs = cmd
.executeQuery(sql);// 表名为user,user_ID和User_ps是存放用户名和密码的字段名
if (rs.next()) {
JOptionPane.showMessageDialog(null, "登陆成功!");
} else
JOptionPane.showMessageDialog(null, "用户名或密码错误!");
} catch (Exception ex) {
}
if (ae.getSource() == btn2) {
System.out.println("1111111111111");
//txt.setText("");
//pf.setText("");
System.exit(0);
}
}
}
public static void main(String arg[]) {
JFrame.setDefaultLookAndFeelDecorated(true);
LoginFrm frm = new LoginFrm();
frm.setSize(400, 200);
frm.setVisible(true);
}
}
新闻名称:java模拟登录注册代码 登录注册页面代码JAVA
文章URL:http://scgulin.cn/article/hjcsop.html