java登陸注冊界面代碼 java登錄注冊界面代碼

如何用Java編寫用戶注冊界面?

界面建議用可視化來做,美觀且便捷。下面這個是完全用代碼寫的,僅供參考。\x0d\x0aimport javax.swing.*;\x0d\x0aimport java.awt.event.*;\x0d\x0aimport java.awt.*;\x0d\x0aimport java.sql.*;\x0d\x0apublic class Register extends JFrame {\x0d\x0a JLabel jl1 = new JLabel("用戶名");\x0d\x0a JTextField jt1 = new JTextField();\x0d\x0a JLabel jl2 = new JLabel("郵箱");\x0d\x0a JTextField jt2 = new JTextField();\x0d\x0a JLabel jl3 = new JLabel("密碼");\x0d\x0a JPasswordField jpw1 = new JPasswordField();\x0d\x0a JLabel jl4 = new JLabel("密碼確認");\x0d\x0a JPasswordField jpw2 = new JPasswordField();\x0d\x0a JButton register = new JButton("注冊");\x0d\x0a JButton clean = new JButton("清空");\x0d\x0a public Register(){\x0d\x0a setLayout(new GridLayout(5,2));\x0d\x0a add(jl1);\x0d\x0a add(jt1);\x0d\x0a add(jl2);\x0d\x0a add(jt2);\x0d\x0a add(jl3);\x0d\x0a add(jpw1);\x0d\x0a add(jl4);\x0d\x0a add(jpw2);\x0d\x0a add(register);\x0d\x0a add(clean);\x0d\x0a String name = jt1.getText();\x0d\x0a String email = jt2.getText();\x0d\x0a String pw = jpw1.getText();\x0d\x0a register.addActionListener(new ActionListener(){\x0d\x0a public void actionPerformed(ActionEvent e){\x0d\x0a try{\x0d\x0a Class.forName("com.mysql.jdbc.Driver");\x0d\x0a Connection con = DriverManager.getConnection("jdbc:mysql://localhost/db","root","");\x0d\x0a Statement sta = con.createStatement();\x0d\x0a sta.executeUpdate("INSERT INTO register VALUES(name,email,pw)");\x0d\x0a JOptionPane.showMessageDialog(null,"注冊成功","提示",JOptionPane.INFORMATION_MESSAGE);\x0d\x0a }\x0d\x0a catch(Exception ex){\x0d\x0a ex.getStackTrace();\x0d\x0a }\x0d\x0a }\x0d\x0a });\x0d\x0a clean.addActionListener(new ActionListener(){\x0d\x0a public void actionPerformed(ActionEvent e){\x0d\x0a jt1.setText("");\x0d\x0a jt2.setText("");\x0d\x0a jpw1.setText("");\x0d\x0a jpw2.setText("");\x0d\x0a }\x0d\x0a });\x0d\x0a }\x0d\x0a public static void main(String[] args){\x0d\x0a Register frame = new Register();\x0d\x0a frame.setTitle("用戶注冊");\x0d\x0a frame.setLocationRelativeTo(null);\x0d\x0a frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\x0d\x0a frame.setSize(400,400);\x0d\x0a frame.setVisible(true);\x0d\x0a }\x0d\x0a}

創(chuàng)新互聯(lián)建站自2013年創(chuàng)立以來,是專業(yè)互聯(lián)網(wǎng)技術服務公司,擁有項目做網(wǎng)站、成都網(wǎng)站制作網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元平定做網(wǎng)站,已為上家服務,為平定各地企業(yè)和個人服務,聯(lián)系電話:18980820575

用java寫一個手機商城注冊界面代碼

這篇文章主要介紹了java通過JFrame做一個登錄系統(tǒng)的界面完整代碼示例,具有一定借鑒價值,需要的朋友可以參考下。

在java的JFrame內(nèi)通過創(chuàng)建匿名對象的方式做登錄界面

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方法里面調(diào)

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);

//注意:此處是匿名內(nèi)部類

bg.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

System.exit(0);

}

}

);

//注意:此處是匿名內(nèi)部類

bl.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {

用JAVA編寫一個用戶或注冊登錄界面。請哪位高手能夠?qū)懴戮唧w的代碼,謝謝

效果圖

代碼

!DOCTYPE?html

html

head

meta?charset="UTF-8"

title先鋒圖書館管理系統(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"先鋒圖書館系統(tǒng)管理平臺/label

/div

/div

div?id="top_bottom"

div?id="top_bottom_left"當前位置?:?首頁??系統(tǒng)管理??登錄/div

div?id="top_bottom_right"當前時間?:?label?id="lable"/label/div

/div

/div

div?id="content"

div?id="text"歡迎登錄先鋒圖書館管理系統(tǒng)/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代碼怎么寫?

import java.awt.*; \x0d\x0aimport javax.swing.*; \x0d\x0aimport java.awt.event.*; \x0d\x0aimport java.sql.*; \x0d\x0a\x0d\x0aclass LoginFrm extends JFrame implements ActionListener \x0d\x0a{ \x0d\x0aJLabel lbl1=new JLabel("用戶名"); \x0d\x0aJLabel lbl2=new JLabel("密碼"); \x0d\x0aJTextField txt=new JTextField(15); \x0d\x0aJPasswordField pf=new JPasswordField(); \x0d\x0aJButton btn1=new JButton("確定"); \x0d\x0aJButton btn2=new JButton("取消"); \x0d\x0a\x0d\x0apublic LoginFrm() \x0d\x0a{ \x0d\x0athis.setTitle("登陸"); \x0d\x0aJPanel jp=(JPanel)this.getContentPane(); \x0d\x0ajp.setLayout(new GridLayout(3,2,10,10)); \x0d\x0ajp.add(lbl1);jp.add(txt); \x0d\x0ajp.add(lbl2);jp.add(pf); \x0d\x0ajp.add(btn1);jp.add(btn2); \x0d\x0abtn1.addActionListener(this); \x0d\x0abtn2.addActionListener(this); \x0d\x0a} \x0d\x0a\x0d\x0apublic void actionPerformed(ActionEvent ae) \x0d\x0a{ \x0d\x0aif(ae.getSource()==btn1) \x0d\x0a{ \x0d\x0atry \x0d\x0a{ \x0d\x0aClass.forName("sun.jdbc.odbc.JdbcOdbcDriver"); \x0d\x0aConnection con=DriverManager.getConnection("jdbc:odbc:MyDB","",""); \x0d\x0aStatement cmd=con.createStatement(); \x0d\x0aResultSet rs=cmd.executeQuery("select * from loginAndpassword where login='"+txt.getText()+"' and password='"+pf.getText()+"'"); \x0d\x0aif(rs.next()) \x0d\x0a{ \x0d\x0aJOptionPane.showMessageDialog(null,"登陸成功!"); \x0d\x0a} \x0d\x0aelse \x0d\x0aJOptionPane.showMessageDialog(null,"用戶名或密碼錯誤!"); \x0d\x0a} catch(Exception ex){} \x0d\x0a\x0d\x0aif(ae.getSource()==btn2) \x0d\x0a{ \x0d\x0atxt.setText(""); \x0d\x0apf.setText(""); \x0d\x0a} \x0d\x0a} \x0d\x0a} \x0d\x0a\x0d\x0apublic static void main(String arg[]) \x0d\x0a{ \x0d\x0aJFrame.setDefaultLookAndFeelDecorated(true); \x0d\x0aLoginFrm frm=new LoginFrm(); \x0d\x0afrm.setSize(400,200); \x0d\x0afrm.setVisible(true); \x0d\x0a} \x0d\x0a}

名稱欄目:java登陸注冊界面代碼 java登錄注冊界面代碼
當前網(wǎng)址:http://www.muchs.cn/article30/dohieso.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供虛擬主機、小程序開發(fā)、關鍵詞優(yōu)化、網(wǎng)站維護、企業(yè)建站、品牌網(wǎng)站設計

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作