189 8069 5689

java登录按钮代码 java用户登录界面设计代码

如何用JAVA编写一个简单用户登陆界面?

什么都不说了 直接给你代码吧\x0d\x0apackage com.moliying.ui;\x0d\x0aimport java.awt.BorderLayout;\x0d\x0aimport java.awt.Container;\x0d\x0aimport java.awt.FlowLayout;\x0d\x0aimport java.awt.List;\x0d\x0aimport java.awt.event.ActionEvent;\x0d\x0aimport java.awt.event.ActionListener;\x0d\x0aimport java.io.BufferedWriter;\x0d\x0aimport java.io.FileOutputStream;\x0d\x0aimport java.io.OutputStreamWriter;\x0d\x0aimport java.util.ArrayList;\x0d\x0aimport java.util.Arrays;\x0d\x0aimport javax.swing.JButton;\x0d\x0aimport javax.swing.JFrame;\x0d\x0aimport javax.swing.JLabel;\x0d\x0aimport javax.swing.JPanel;\x0d\x0aimport javax.swing.JPasswordField;\x0d\x0aimport javax.swing.JTextField;\x0d\x0apublic class Login {\x0d\x0aprivate JFrame frame = new JFrame("登录");\x0d\x0aprivate Container c = frame.getContentPane();\x0d\x0aprivate JTextField username = new JTextField();\x0d\x0aprivate JPasswordField password = new JPasswordField();\x0d\x0aprivate JButton ok = new JButton("确定");\x0d\x0aprivate JButton cancel = new JButton("取消");\x0d\x0apublic Login() {\x0d\x0aframe.setSize(300, 200);\x0d\x0aframe.setBounds(450, 300, 300, 200);\x0d\x0ac.setLayout(new BorderLayout());\x0d\x0ainitFrame();\x0d\x0aframe.setVisible(true);\x0d\x0a}\x0d\x0aprivate void initFrame() {\x0d\x0a// 顶部\x0d\x0aJPanel titlePanel = new JPanel();\x0d\x0atitlePanel.setLayout(new FlowLayout());\x0d\x0atitlePanel.add(new JLabel("系统管理员登录"));\x0d\x0ac.add(titlePanel, "North");\x0d\x0a// 中部表单\x0d\x0aJPanel fieldPanel = new JPanel();\x0d\x0afieldPanel.setLayout(null);\x0d\x0aJLabel a1 = new JLabel("用户名:");\x0d\x0aa1.setBounds(50, 20, 50, 20);\x0d\x0aJLabel a2 = new JLabel("密 码:");\x0d\x0aa2.setBounds(50, 60, 50, 20);\x0d\x0afieldPanel.add(a1);\x0d\x0afieldPanel.add(a2);\x0d\x0ausername.setBounds(110, 20, 120, 20);\x0d\x0apassword.setBounds(110, 60, 120, 20);\x0d\x0afieldPanel.add(username);\x0d\x0afieldPanel.add(password);\x0d\x0ac.add(fieldPanel, "Center");\x0d\x0a// 底部按钮\x0d\x0aJPanel buttonPanel = new JPanel();\x0d\x0abuttonPanel.setLayout(new FlowLayout());\x0d\x0abuttonPanel.add(ok);\x0d\x0abuttonPanel.add(cancel);\x0d\x0ac.add(buttonPanel, "South");\x0d\x0a\x0d\x0aok.addActionListener(new ActionListener() {\x0d\x0a\x0d\x0a@Override\x0d\x0apublic void actionPerformed(ActionEvent e) {\x0d\x0aSystem.out.println(username.getText().toString());\x0d\x0a}\x0d\x0a});\x0d\x0a\x0d\x0acancel.addActionListener(new ActionListener() {\x0d\x0a\x0d\x0a@Override\x0d\x0apublic void actionPerformed(ActionEvent e) {\x0d\x0aframe.setVisible(false);\x0d\x0a}\x0d\x0a});\x0d\x0a}\x0d\x0apublic static void main(String[] args) {\x0d\x0a//new Login();\x0d\x0a\x0d\x0aString ss = "abbabbbaabbbccba";\x0d\x0a\x0d\x0aSystem.out.println(ss.split("b").length);\x0d\x0a\x0d\x0a}\x0d\x0a}

在木兰等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都网站建设、网站建设 网站设计制作按需求定制制作,公司网站建设,企业网站建设,高端网站设计,营销型网站,成都外贸网站建设公司,木兰网站建设费用合理。

用JAVA如何制做一个简单的登录界面?就是有用户名、密码、确定和取消按钮、最好有注册按钮。给代码。谢谢

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

html

head

title无标题文档/title

script language="javascript"

function fsubmit(obj)

{

obj.submit();

}

function freset(obj){

obj.reset();

}

/script

/head

body bgcolor="#333333"

form id="form1" name="form1" method="post" action="conn.jsp"

table width="745" border="0" align="center"

tr

td width="100" /td

td /td

td width="104" /td

/tr

tr

td /td

td width="527" height="297" background="img/LoginBg.jpg" bgcolor="#F0F0F0"

table width="358" border="0"

tr

td width="70" height="51" /td

td width="119" /td

td width="160" /td

/tr

tr

td height="46" /td

tdfont color="#FFFFFF"用户名:/font/td

tdinput type="text" name="user" style=" width:160px" id="user" //td

/tr

tr

td height="34" /td

tdfont color="#FFFFFF"密  码:/font/td

tdinput type="password" name="pswd" style="width:160px" id="pswd" //td

/tr

tr

td height="24" /td

td /td

td /td

/tr

/table

table width="396" border="0"

tr

td width="82" height="30" /td

td width="114"img src="img/loginbutton.jpg" style="cursor:hand;" onclick="javascript:fsubmit(document.form1);"/td

td width="41" /td

td width="141"img src="img/canclebutton.jpg" style="cursor:hand;" onclick="javascript:freset(document.form1);"/td

/tr

/table /td

td /td

/tr

tr

td /td

td /td

td /td

/tr

/table

/form

/body

/html

%@ page language="java" import="java.util.*" contentType="text/html;charset=GB2312" import="java.sql.*"%

%@ page import="com.microsoft.sqlserver.jdbc.SQLServerDriver" %

%@page import="java.sql.DriverManager"%

HTML

HEAD

/HEAD

body

%

String userName=request.getParameter("user");

String Pswd =request.getParameter("pswd");

try

{

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();

}

catch(ClassNotFoundException e)

{

out.print("0");

out.print(e.toString());

}

try

{

Connection con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=RegUser","sa","123");

Statement stmt = con.createStatement();

String sql="select * from tb_user";

ResultSet rs=stmt.executeQuery(sql);

while(rs.next())

{

if(userName.equals(rs.getString(2))Pswd.equals(rs.getString(3)))

{

rs.close();

stmt.close();

con.close();

%

jsp:forward page="index.html" /jsp:forward

%

}

}

rs.close();

stmt.close();

con.close();

%

script type="text/javascript"

if(!confirm("用户名或密码错误,是否要转入注册页"))

{

location.href="MyHtml.html";

}

else

{

location.href="Register.html";

}

/script

%

}

catch(Exception e)

{

out.print("1");

out.print(e.toString());

}

%

/body

/HTML

java实现简单登录界面,就是按个按钮就能从一个JFRAME跳转到另一个,基本就是按登录就能跳转

java实现的简单登录页面,从一个按钮点击后跳转的页面的jframe写法:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class jb{

public static void main(String args[]){

JFrame f=new JFrame("点我跳转");

Container contentPane=f.getContentPane();

contentPane.setLayout(new GridLayout(1,2));

Icon icon=new ImageIcon("b.jpg");

JLabel label2=new JLabel("a",icon,JLabel.CENTER);

label2.setHorizontalTextPosition(JLabel.CENTER);

contentPane.setLayout(new FlowLayout( FlowLayout.CENTER,10,10));

JButton bb=new JButton("图片");

bb.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

JFrame bf=new JFrame("新窗体");

Icon icon=new ImageIcon("enter.jpg");

JLabel label2=new JLabel(icon);

bf.getContentPane().add(label2);

bf.setSize(300,360);

bf.show();

}});

contentPane.add(label2);

contentPane.add(bb);

f.pack();

f.show();

}}

求java语言的一个按钮登录代码

点击进入js,将user和pwd通过ajax调用后台java代码去判断并根据返回值判断正确则window.location.href打开新的页面

java设计个登陆页面,要求点击登录按钮时,判断用户名和密码是不是都为“123”,如果是的话,就输出“登录

楼上的辛苦了,但帮人帮到底,再加点注释,更容易理解

public class LoginFrame extends JFrame {

JTextField jtf1;

JTextField jtf2;

//构造方法,调用初始化方法

public LoginFrame() {

init();

}

//初始化当前的frame

private void init(){

//下面的方法都是从Frame继承的,用来设置Frame的标题,位置和大小

setTitle("QQ登录");

setLocation(300, 200);

setSize(300, 200);

//设置内容面板

setContentPane(createContentPane());

}

//设置内容面板

private JPanel createContentPane(){

JPanel pane = new JPanel(new BorderLayout(0,8));

pane.setBorder(new EmptyBorder(12,12,12,12));

pane.add(BorderLayout.NORTH,

new JLabel("", JLabel.CENTER));

pane.add(BorderLayout.CENTER,

createNamePwdPane());

pane.add(BorderLayout.SOUTH,

createBtnPane());

return pane;

}

//这下面都是创建用户名、密码标签和文本框,然后加到面板上显示

private JPanel createNamePwdPane(){

JPanel pane = new JPanel(new BorderLayout());

JPanel top = new JPanel(new GridLayout(2,1,0,6));

pane.add(BorderLayout.NORTH, top);

top.add(createNamePane());

top.add(createPwdPane());

return pane;

}

private JPanel createNamePane(){

JPanel pane = new JPanel(new BorderLayout(4,0));

pane.add(BorderLayout.WEST,

new JLabel("用户名:"));

jtf1= new JTextField();

pane.add(BorderLayout.CENTER,

jtf1);

return pane;

}

private JPanel createPwdPane(){

JPanel pane = new JPanel(new BorderLayout(4,0));

pane.add(BorderLayout.WEST,

new JLabel("密 码:"));

jtf2= new JPasswordField();

pane.add(BorderLayout.CENTER,jtf2 );

return pane;

}

private JPanel createBtnPane(){

JPanel pane = new JPanel(new FlowLayout());

JButton login = new JButton("登录");

login.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

//这里才是楼主要的关键代码,getText()是得到用户输入的文本内容,判断是否等于123

if(jtf2.getText().equals("123")jtf1.getText().equals("123")){

System.out.println("登录 ");

//不等就输出登录失败

}else{

System.out.println("登录失败");

}

}

});

//创建退出按钮

JButton cancel = new JButton("退出");

//给退出按钮加监听,点击该按钮时就退出系统

cancel.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

System.exit(0);

}

});

pane.add(login);

pane.add(cancel);

return pane;

}

public void showView(){

setVisible(true);

}

public static void main(String[] args) {

LoginFrame lf=new LoginFrame();

lf.showView();

}

}


当前名称:java登录按钮代码 java用户登录界面设计代码
地址分享:http://cdxtjz.cn/article/dossgid.html

其他资讯