你這個(gè)不用數(shù)據(jù)庫(kù)真的是有點(diǎn)難搞
創(chuàng)新互聯(lián)專(zhuān)注于企業(yè)成都全網(wǎng)營(yíng)銷(xiāo)推廣、網(wǎng)站重做改版、信州網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5網(wǎng)站設(shè)計(jì)、成都做商城網(wǎng)站、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)營(yíng)銷(xiāo)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性?xún)r(jià)比高,為信州等各大城市提供網(wǎng)站開(kāi)發(fā)制作服務(wù)。
我寫(xiě)了個(gè)用集合存儲(chǔ)的,你看看,能否幫上你
java.util.ListString?list?=?new?ArrayListString();
list.add("qq=123");//存儲(chǔ)的時(shí)候用(用戶(hù)名=密碼)的形式
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;
}
}
你要先學(xué)會(huì)截圖哦,你發(fā)的看不清楚,重新寫(xiě)了一個(gè)你參考參考!
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("注冊(cè)賬戶(hù)");
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="卡片類(lèi)型1,卡片類(lèi)型2,卡片類(lèi)型3,卡片類(lèi)型4,卡片類(lèi)型5";
jcb=new JComboBox(str.split(","));
labelId=new JLabel("賬號(hào): ");
labelName=new JLabel("姓名: ");
labelPass=new JLabel("密碼: ");
labelMoney=new JLabel("開(kāi)戶(hù)金額:");
labelSelect=new JLabel("存款類(lèi)型:");
labelCar=new JLabel("卡片類(lèi)型:");
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();
}
}
這是我自己做的一個(gè)管理系統(tǒng)的登錄界面,代碼雖然有點(diǎn)繁瑣,不過(guò)簡(jiǎn)單易懂,你根據(jù)自己的需要進(jìn)行修改吧。
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JDialog;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
/**
*
* @author mzhe
*
*/
class Loginfrm extends JDialog implements ActionListener
{
JLabel l_name,l_pass,l_error;
JTextField t_name;
JButton b_enter,b_cancle,b_clear;
JPanel pan1,pan2,pan3,pan4;
JPasswordField t_pass;
String sname,spass;
int sunit;
NetConn sql;
Statement sqll;
ResultSet rs;
Librarybox lbox;
int until=0;
Loginfrm(JFrame f,String s)
{
//界面布局
super(f,s);
l_name=new JLabel("名字:");
l_pass=new JLabel("密碼:");
l_error=new JLabel("請(qǐng)輸入用戶(hù)名和密碼登錄");
t_name=new JTextField("",10);
t_pass=new JPasswordField("",10);
t_pass.setEchoChar('*');
b_enter=new JButton("確定");
b_enter.addActionListener(this);
b_cancle=new JButton("取消");
b_cancle.addActionListener(this);
b_clear=new JButton("清除");
b_clear.addActionListener(this);
pan1=new JPanel();
pan2=new JPanel();
pan3=new JPanel();
pan4=new JPanel();
pan1.add(l_name);pan1.add(t_name);
pan2.add(l_pass);pan2.add(t_pass);
pan3.add(l_error);
pan4.add(b_enter);pan4.add(b_cancle);pan4.add(b_clear);
setLayout(new GridLayout(4,1));
add(pan1);add(pan2);add(pan3);add(pan4);
//建立數(shù)據(jù)庫(kù)連接
sql=new NetConn();
//設(shè)置窗口大小
setSize(300,300);
setVisible(false);
//得到屏幕信息以便使框架居中顯示
Dimension screeSize = Toolkit.getDefaultToolkit().getScreenSize();
int screeWidth=screeSize.width;
int screeHeight=screeSize.height;
//得到框架的大小信息
Dimension frameSize=this.getSize();
int x=(screeWidth-frameSize.width)/2;
int y=(screeHeight-frameSize.height)/2;
this.setLocation(x, y);
}
public void actionPerformed(ActionEvent e)
{
//單擊確定按鈕的事件處理程序
if(e.getSource()==b_enter)
{
//如果連續(xù)登錄次數(shù)小于4
if(until=4)
{
//如果用戶(hù)名或者密碼為空,將顯示提示信息
if(t_name.getText().equals("")||t_pass.getText().equals(""))
{
l_error.setText("用戶(hù)名和密碼不能為空");
}
else
{
try
{
sqll=sql.connect();
//根據(jù)用戶(hù)名查詢(xún)
rs=sqll.executeQuery("SELECT * FROM users where username="+"'"+t_name.getText()+"'");
//遍歷查詢(xún)得到的結(jié)果集
while(rs.next())
{
sname=rs.getString(2);
spass=rs.getString(3);
//得到登錄用戶(hù)的級(jí)別
sunit=Integer.parseInt(rs.getString(4));
//如果密碼正確
if(t_pass.getText().equals(spass))
{
//判斷用戶(hù)的級(jí)別,根據(jù)不同的級(jí)別,顯示不同的菜單
switch(sunit)
{
case 1:
{
l_error.setText("登錄成功");
t_name.setText("");
t_pass.setText("");
lbox=new Librarybox();
lbox.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
lbox.setResizable(false);
lbox.bookfi.setEnabled(true);
lbox.bookse.setEnabled(true);
lbox.bookth.setEnabled(true);
lbox.bookfo.setEnabled(true);
lbox.mi_system_manger.setEnabled(true);
lbox.mi_system_login.setEnabled(false);
lbox.setVisible(true);
this.dispose();
break;
}
case 2:
{
l_error.setText("登錄成功");
t_name.setText("");
t_pass.setText("");
lbox=new Librarybox();
lbox.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
lbox.setResizable(false);
lbox.bookfi.setEnabled(false);
lbox.bookse.setEnabled(false);
lbox.bookth.setEnabled(true);
lbox.bookfo.setEnabled(false);
lbox.mi_system_manger.setEnabled(false);
lbox.mi_system_login.setEnabled(false);
lbox.setVisible(true);
this.dispose();
break;
}
case 3:
{
l_error.setText("登錄成功");
t_name.setText("");
t_pass.setText("");
lbox=new Librarybox();
lbox.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
lbox.setResizable(false);
lbox.bookfi.setEnabled(true);
lbox.bookse.setEnabled(false);
lbox.bookth.setEnabled(false);
lbox.bookfo.setEnabled(true);
lbox.mi_system_manger.setEnabled(false);
lbox.mi_system_login.setEnabled(false);
lbox.fi_msglabel_user.setEnabled(false);
lbox.setVisible(true);
this.dispose();
break;
}
}
}
else
{
l_error.setText("用戶(hù)名或密碼錯(cuò)誤!");
until++;
}
}
}
catch(SQLException e2)
{
e2.printStackTrace();
}
}
}
//超出登錄次數(shù)
else
{
l_error.setText("你已經(jīng)超出登錄次數(shù)");
t_name.setEnabled(false);
t_pass.setEnabled(false);
b_enter.setEnabled(false);
b_clear.setEnabled(false);
}
}
//單擊清除按鈕的事件處理程序
else if(e.getSource()==b_clear)
{
t_name.setText("");
t_pass.setText("");
l_error.setText("請(qǐng)輸入用戶(hù)名和密碼登錄");
}
//單擊取消按鈕的事件處理程序
else if(e.getSource()==b_cancle)
{
dispose();
}
}
}
如果你比較認(rèn)可的話(huà),請(qǐng)采納吧,不給分也沒(méi)關(guān)系。只希望對(duì)你有用。
效果圖
代碼
!DOCTYPE?html
html
head
meta?charset="UTF-8"
title先鋒圖書(shū)館管理系統(tǒng)-登錄/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"先鋒圖書(shū)館系統(tǒng)管理平臺(tái)/label
/div
/div
div?id="top_bottom"
div?id="top_bottom_left"當(dāng)前位置?:?首頁(yè)??系統(tǒng)管理??登錄/div
div?id="top_bottom_right"當(dāng)前時(shí)間?:?label?id="lable"/label/div
/div
/div
div?id="content"
div?id="text"歡迎登錄先鋒圖書(shū)館管理系統(tǒng)/div
div?id="login"
img?src="img/test/a14.png"??width="175px"?height="210px"/
form?id="select"
div?id="d1"用戶(hù)名:?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"欣欣科技有限公司版權(quán)所有/div
/body
script?type="text/javascript"?src="JQuery/jquery.js"/script
script?type="text/javascript"?src="js/GetCurrentTime.js"/script
script
//驗(yàn)證用戶(hù)名和密碼
function?put(){
var?d?=?$("#selectdivinput");//獲取用戶(hù)名和密碼
var?name?=?d[0].value;
var?pass?=?d[1].value;
var?user?=?null;
var?r?=?document.getElementsByName("user");//獲取用戶(hù)類(lèi)型
for(i=0;ir.length;i++){
if(r[i].checked){
user=r[i].value;
}
}
//console.log(name?+?","?+pass?+?","?+user);//輸出測(cè)試
if(user==null){
window.alert("請(qǐng)選擇用戶(hù)類(lèi)型!");
}else?if(user=="admin"??name!="admin"){
window.alter("用戶(hù)名錯(cuò)誤!");
}else?if(user=="admin"??name=="admin"??pass!="123456"){
window.alert("密碼錯(cuò)誤!");
}else?if(name=="admin"??pass=="123456"??user=="admin"){
window.location.href="work_02_welcome.html";//在js中在本頁(yè)面中打開(kāi)新鏈接
}else{
window.alert("用戶(hù)名錯(cuò)誤");
}
}
/script
/html
什么都不說(shuō)了 直接給你代碼吧
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("系統(tǒng)管理員登錄"));
c.add(titlePanel, "North");
// 中部表單
JPanel fieldPanel = new JPanel();
fieldPanel.setLayout(null);
JLabel a1 = new JLabel("用戶(hù)名:");
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);
}
}
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("用戶(hù)名:");
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,"密碼輸入錯(cuò)誤,請(qǐng)?jiān)僭囈淮?);
error++;
}
else{
JOptionPane.showMessageDialog(null,"對(duì)不起,您不是合法用戶(hù)");
txt.setEnabled(false);
pwd.setEnabled(false);
btn.setEnabled(false);
}
}
}
});
}
public?static?void?main(String[]?args)?{
MainFrame?frm?=?new?MainFrame("測(cè)試");
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setBounds(100,?100,?300,?120);
frm.setVisible(true);
}
}
文章名稱(chēng):java用戶(hù)注冊(cè)登錄代碼 java登錄注冊(cè)完整代碼
鏈接URL:http://muchs.cn/article12/doccedc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、標(biāo)簽優(yōu)化、自適應(yīng)網(wǎng)站、移動(dòng)網(wǎng)站建設(shè)、電子商務(wù)、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
全網(wǎng)營(yíng)銷(xiāo)推廣知識(shí)