成都创新互联网站制作重庆分公司

java简易用户登录代码 java实现用户名密码登录

java写的用户登陆实例,用eclipse开发的具体步奏和代码

import java.awt.Container;

为市中等地区用户提供了全套网页设计制作服务,及市中网站建设行业解决方案。主营业务为网站制作、成都网站制作、市中网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

import java.awt.Font;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;import javax.swing.*;public class Login extends JFrame{

JLabel user,passwd;

JTextField userput;

JPasswordField passput;

JButton denglu,tuichu;

public Login(){

super("用户登录");

Container c=getContentPane();

c.setLayout(null);

Font f=new Font("宋体",Font.PLAIN,12);

user=new JLabel("账号");

passwd=new JLabel("密码");

userput=new JTextField();

passput=new JPasswordField();

denglu=new JButton("登录");

denglu.setFont(f);

denglu.addActionListener(new NewAction());

tuichu=new JButton("退出");

tuichu.setFont(f);

tuichu.addActionListener(new NewAction());

user.setBounds(50,50,60,20);

userput.setBounds(110,50,150,20);

passwd.setBounds(50,80,60,20);

passput.setBounds(110,80,150,20);

denglu.setBounds(50,160,60,30);

tuichu.setBounds(200,160,60,30);

c.add(user);

c.add(userput);

c.add(passwd);

c.add(passput);

c.add(denglu);

c.add(tuichu);

setSize(350, 300);

setVisible(true);

}

class NewAction implements ActionListener{

String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=CDM";

String user="sa";

String passwd="394513265";

java.sql.Connection con;

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

try{

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

con= DriverManager.getConnection(url,user,passwd);

}catch(Exception ep){

JOptionPane.showMessageDialog(null, "加载驱动失败!");

}

if(e.getSource()==denglu){

Find();

}

if(e.getSource()==tuichu){

dispose();

}

} public void Find(){

String lk="select * from login";

try{

Statement sql=con.createStatement();

ResultSet rs=sql.executeQuery(lk);

while(rs.next()){

if(rs.getString(1).equals(userput.getText()) rs.getString(2).equals(passput.getText()))

new MainClient();

else

JOptionPane.showMessageDialog(null, "用户名或密码错误");

}

rs.close();

}catch(SQLException p){

JOptionPane.showMessageDialog(null, p.getMessage());

}

}

}

public static void main(String[] args) {

Login l=new Login();

l.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

步骤就是建个工程 然后建个class

如何用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实现用户登录界面代码?

你要先学会截图哦,你发的看不清楚,重新写了一个你参考参考!

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("注册账户");

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="卡片类型1,卡片类型2,卡片类型3,卡片类型4,卡片类型5";

jcb=new JComboBox(str.split(","));

labelId=new JLabel("账号: ");

labelName=new JLabel("姓名: ");

labelPass=new JLabel("密码: ");

labelMoney=new JLabel("开户金额:");

labelSelect=new JLabel("存款类型:");

labelCar=new JLabel("卡片类型:");

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

}

}


当前题目:java简易用户登录代码 java实现用户名密码登录
本文网址:http://cxhlcq.com/article/docdope.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部