资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java创建注册界面代码 java web注册界面实现源代码

用java写一个手机商城注册界面代码

这篇文章主要介绍了java通过JFrame做一个登录系统的界面完整代码示例,具有一定借鉴价值,需要的朋友可以参考下。

10余年的青川网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。网络营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整青川建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“青川网站设计”,“青川网站推广”以来,每个客户项目都认真落实执行。

在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) {

用java web编写一个用户注册界面(只要写出以下要求就行)

一步步更新:页面

form action="regist.servlet" method="post"table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" class="tableAdd borTop" tr th width="14%" height="30" nowrap用户名/th td class="pl5" INPUT id="sName" name="name" type="text" size="20" /td /tr tr th width="14%" height="30" nowrap密码/th td class="pl5" INPUT name="password" type="password" size="20" /td /tr tr th width="14%" height="30" nowrap确认密码/th td class="pl5" INPUT name="confrimPwd" type="password" size="20" /td /tr tr th width="14%" height="30" nowrap性别/th td class="pl5" 男INPUT name="sex" type="radio" value="1" checked="checked" size="20" 女INPUT name="sex" type="radio" value="0" size="20" /td /tr tr th width="14%" height="30" nowrap爱好/th td class="pl5" INPUT name="enjoy" type="checkbox" size="20" value="篮球"篮球 INPUT name="enjoy" type="checkbox" size="20" value="足球"足球 /td /tr tr th width="14%" height="30" nowrap生日/th td class="pl5" INPUT name="brithday" type="text" size="20" /td /tr tr th width="14%" height="30" nowrap备注/th td class="pl5" textarea rows="5" cols="200" name="remark"/textarea /td /tr tr th width="14%" height="30" nowrap /th td class="pl5" input type="submit" value="提交" input type="reset" value="重置" /td /tr/table/form

数据库部分:

import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import com.mysql.jdbc.Connection;import com.mysql.jdbc.Statement;public class DataBaseUtil { public static Connection getConnection() throws ClassNotFoundException, SQLException { Class.forName("com.mysql.jdbc.Driver"); Connection conn = (Connection) DriverManager.getConnection("jdbc:mysql://192.168.100.113/datebase", "username", "password"); return conn; } public static Statement getPS() throws ClassNotFoundException, SQLException { Statement statement = (Statement) getConnection().createStatement(); return statement; } public static void close(Connection conn,Statement st,ResultSet rs) throws SQLException{ if(rs != null) { rs.close(); } if(st != null) { st.close(); } if(conn != null) { conn.close(); } }}

用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写一个用户注册界面,点击确认后,可保存在文件中

昨天刚好有人提问了一个类似的问题,我把昨天的回答发给你,供你参考 , 主要是思路, 如果是作业的话, 最好不要和同学相同, 自己理解后, 重新写1个,会比较好

效果图

参考代码和注释

import java.awt.*;

import java.awt.event.*;

import java.io.*;

import javax.swing.*;

//该窗口继承自JFrame, 实现了ActionListener接口

public class SingUpFrame extends JFrame implements ActionListener {

//定义需要的组件

JTextField jtfName, jtfEmail; 

JPasswordField jpf;

JRadioButton jrb1, jrb2;

JComboBoxString jcb;

JButton jbReset, jbSingUp;

//常量

public static final String NEW_LINE = System.getProperty("line.separator");// 获取系统的换行符

public static final String FILE_PATH = "d:/users.txt";//指定文件的路径

//构造器

public SingUpFrame() {

JPanel jp1 = new JPanel();

JLabel jl1 = new JLabel("账号");

jtfName = new JTextField(15);

jp1.add(jl1);

jp1.add(jtfName);

JPanel jp2 = new JPanel();

JLabel jl2 = new JLabel("密码");

jpf = new JPasswordField(15);

jp2.add(jl2);

jp2.add(jpf);

JPanel jp3 = new JPanel();

JLabel jl3 = new JLabel("邮箱");

jtfEmail = new JTextField(15);

jp3.add(jl3);

jp3.add(jtfEmail);

JPanel jp4 = new JPanel();

JLabel jl4 = new JLabel("性别");

ButtonGroup bg = new ButtonGroup();

jrb1 = new JRadioButton("男");

jrb1.setSelected(true);// 默认选中男性

jrb2 = new JRadioButton("女");

bg.add(jrb1);

bg.add(jrb2);

jp4.add(jl4);

jp4.add(jrb1);

jp4.add(jrb2);

JLabel jl5 = new JLabel("年龄");

String[] ary = new String[12];

for (int i = 18; i  30; i++) {// 18~30可供选中的范围

ary[i - 18] = i + "";

}

jcb = new JComboBoxString(ary);

jp4.add(jl5);

jp4.add(jcb);

JPanel jpc = new JPanel(new GridLayout(4, 1));// 4行1列布局

jpc.add(jp1);

jpc.add(jp2);

jpc.add(jp3);

jpc.add(jp4);

add(jpc);

JPanel jps = new JPanel();

jbReset = new JButton("重填");

jbReset.addActionListener(this);//给按钮添加响应

jbSingUp = new JButton("确定");

jbSingUp.addActionListener(this);//给按钮添加响应

jps.add(jbReset);

jps.add(jbSingUp);

add(jps, BorderLayout.SOUTH);

setTitle("注册窗口");// 窗口标题

setSize(300, 285);// 窗口大小

setLocationRelativeTo(null);// 窗口居中

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 当窗口关闭时,程序结束

}

@Override

public void actionPerformed(ActionEvent e) {

JButton jb = (JButton) e.getSource();

if (jb == jbReset) {

jtfName.setText("");

jpf.setText("");

jtfEmail.setText("");

jrb1.setSelected(true);

jcb.setSelectedIndex(0);// 选中第1个选项(18)

} else if (jb == jbSingUp) {

String name = jtfName.getText().trim();

String pswd = new String(jpf.getPassword());

String email = jtfEmail.getText().trim();

String xb = jrb1.isSelected() ? "男" : "女";

String age = (String) jcb.getSelectedItem();

if(name.equals("")||pswd.equals("")||email.equals("")) {//对输入的信息进行一个简单的判断

JOptionPane.showMessageDialog(null, "请完整填写所有的信息", "提示",JOptionPane.WARNING_MESSAGE);  

return;

}

StringBuffer sb = new StringBuffer();

sb.append("账号:" + name + NEW_LINE + "密码:" + pswd + NEW_LINE + "邮箱:" + email + NEW_LINE + "性别:" + xb

+ NEW_LINE + "年龄:" + age+NEW_LINE);

boolean flag = saveInfo(sb.toString());

if(flag) {

JOptionPane.showMessageDialog(null, "注册成功 ,保存成功");

}else {

JOptionPane.showMessageDialog(null, "Sorry!保存失败.注册出现了问题...", "IO错误",JOptionPane.ERROR_MESSAGE);

}

}

}

//方法:保存信息到文件

public boolean saveInfo(String info) {

FileWriter fw;

try {

fw = new FileWriter(FILE_PATH, true);//追加文字到文件尾部

fw.write(info);

fw.close();

} catch (IOException e) {

e.printStackTrace();

return false;//IO异常,保存不成功

}

return true;//保存成功

}

//main方法

public static void main(String[] args) {

new SingUpFrame().setVisible(true); //创建窗口并可见

}

}


文章题目:java创建注册界面代码 java web注册界面实现源代码
本文来源:http://cdkjz.cn/article/ddedcpc.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220