当前位置:首页 > 代码 > 正文

java登陆界面源代码(java登入界面代码)

admin 发布:2022-12-19 14:46 106


今天给各位分享java登陆界面源代码的知识,其中也会对java登入界面代码进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

求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写一个登录界面的代码,哪位大神会啊,谢谢。

import java.awt.Dimension;

import java.awt.Toolkit;

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.JOptionPane;

import javax.swing.JPasswordField;

import javax.swing.JTextField;

public class Test26 {

public static void main(String[] args) {

final String userName = "abc";

final String passwrod = "123";

JFrame jFrame = new JFrame("登陆界面");

Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();

jFrame.setBounds(((int)dimension.getWidth() - 200) / 2, ((int)dimension.getHeight() - 300) / 2, 200, 150);

jFrame.setResizable(false);

jFrame.setLayout(null);

jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JLabel label1 = new JLabel("姓名");

label1.setBounds(10, 10, 100, 30);

jFrame.add(label1);

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

label2.setBounds(10, 40, 100, 30);

jFrame.add(label2);

final JTextField text1 = new JTextField();

text1.setBounds(50, 15, 130, 20);

jFrame.add(text1);

final JPasswordField text2 = new JPasswordField();

text2.setBounds(50, 45, 130, 20);

jFrame.add(text2);

JButton button = new JButton("Login");

button.setBounds(10, 75, 170, 40);

button.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

if(userName.equals(text1.getText())  passwrod.equals(text2.getText())) {

JOptionPane.showMessageDialog(null, "登陆成功误", "提示", JOptionPane.INFORMATION_MESSAGE);

} else {

JOptionPane.showMessageDialog(null, "错误", "提示", JOptionPane.ERROR_MESSAGE);

text1.setText("");

text2.setText("");

}

}

});

jFrame.add(button);

jFrame.setVisible(true);

}

}

我有一个微信公众号,经常会分享一些Java技术相关的干货,还有一些学习资源。

如果你喜欢我的分享,可以用微信搜索“Java团长”或者“javatuanzhang”关注。

用java程序编写一个简单的登录界面怎么写?

程序如下:

mport java.awt.HeadlessException;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.ImageIcon;

import javax.swing.JButton;

@SuppressWarnings("serial")

public class MainFrame extends JFrame {

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

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

btn.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

if ("admin".equal花憨羔窖薏忌割媳公颅s(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,"密码输入错误,请再试一次");

error++;

}

else{

JOptionPane.showMessageDialog(null,"对不起,您不是合法用户");

txt.setEnabled(false);

pwd.setEnabled(false);

btn.setEnabled(false);

}

}

}

});

}

public static void main(String[] args) {

MainFrame frm = new MainFrame("测试");

frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frm.setBounds(100, 100, 300, 120);

frm.setVisible(true);

}

}

编程的注意事项:

1、Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程。

2、 Java具有简单性、面向对象、分布式、健壮性、安全性、平台独立与可移植性、多线程、动态性等特点。Java可以编写桌面应用程序、Web应用程序、分布式系统和嵌入式系统应用程序等。

3、2006年11月13日,Java技术的发明者Sun公司宣布,将Java技术作为免费软件对外发布。Sun公司正式发布的有关Java平台标准版的第一批源代码,以及Java迷你版的可执行源代码。从2007年3月起,全世界所有的开发人员均可对Java源代码进行修改。

用java怎么实现QQ登录界面?

用java做QQ登录界面的写法如下:

package ch10;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

1、//定义该类继承自JFrame,实现ActionListener接口

public class LoginTest extends JFrame implements ActionListener

{

2、//创建JPanel对象

private JPanel jp=new JPanel();

3、//创建3个标并加入数组

JLabel name = new JLabel("请输入用户名");

JLabel password = new JLabel("请输入密码");

JLabel show = new JLabel("");

private JLabel[] jl={name,password,show};

4、//创建登陆和重置按扭并加入数组

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

JButton reset = new JButton("重置");

private JButton[] jb={login,reset};

5、//创建文本框以及密码框

private JTextField jName=new JTextField();

private JPasswordField jPassword =new JPasswordField();

public LoginTest()

{

6、//设置布局管理器为空布局,这里自己摆放按钮、标签和文本框

jp.setLayout(null);

for(int i=0;i2;i++)

{

7、//设置标签和按扭的位置与大小

jl[i].setBounds(30,20+40*i,180,20);

jb[i].setBounds(30+110*i,100,80,20);

8、//添加标签和按扭到JPanel容器中

jp.add(jl[i]);

jp.add(jb[i]);

//为2个按钮注册动作事件监听器

jb[i].addActionListener(this);

}

9、//设置文本框的位置和大小,注意满足美观并足够用户名的长度

jName.setBounds(130,15,100,20);

10、//添加文本框到JPanel容器中

jp.add(jName);

11、//为文本框注册动作事件监听器

jName.addActionListener(this);

12、//设置密码框的位置和大小,注意满足美观和足够密码的长度

jPassword.setBounds(130,60,100,20);

13、//添加密码框到JPanel容器中

jp.add(jPassword);

14、//设置密码框中的回显字符,这里设置美元符号

jPassword.setEchoChar('$');

15、//为密码框注册动作事件监听器

jPassword.addActionListener(this);

16、//设置用于显示登陆状态的标签大小位置,并将其添加进JPanel容器

jl[2].setBounds(10,180,270,20);

jp.add(jl[2]);

17、//添加JPanel容器到窗体中

this.add(jp);

18、//设置窗体的标题、位置、大小、可见性及关闭动作

this.setTitle("登陆窗口");

this.setBounds(200,200,270,250);

this.setVisible(true);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

19、//实现动作监听器接口中的方法actionPerformed

public void actionPerformed(ActionEvent e)

{

20、//如果事件源为文本框

if(e.getSource()==jName)

{

21、//切换输入焦点到密码框

jPassword.requestFocus();

}

22、//如果事件源为重置按扭

else if(e.getSource()==jb[1])

{

23、//清空姓名文本框、密码框和show标签中的所有信息

jl[2].setText("");

jName.setText("");

jPassword.setText("");

24、//让输入焦点回到文本框

jName.requestFocus();

}

25、//如果事件源为登陆按钮,则判断登录名和密码是否正确

else

{

26、//判断用户名和密码是否匹配

if(jName.getText().equals("lixiangguo")

String.valueOf(jPassword.getPassword()).equals("19801001"))

{

27、jl[2].setText("登陆成功,欢迎您的到来!");

}

else

{

28、jl[2].setText("对不起,您的用户名或密码错误!");

}

}

}

public static void main(String[] args)

{

29、//创建LoginTest窗体对象

new LoginTest();

}

}

java实现简单登录界面

自己写的比较规范的代码,都有注释:

import javax.swing.JFrame;//框架

import javax.swing.JPanel;//面板

import javax.swing.JButton;//按钮

import javax.swing.JLabel;//标签

import javax.swing.JTextField;//文本框

import java.awt.Font;//字体

import java.awt.Color;//颜色

import javax.swing.JPasswordField;//密码框

import java.awt.event.ActionListener;//事件监听

import java.awt.event.ActionEvent;//事件处理

import javax.swing.JOptionPane;//消息窗口

public class UserLogIn extends JFrame{

public JPanel pnluser;

public JLabel lbluserLogIn;

public JLabel lbluserName;

public JLabel lbluserPWD;

public JTextField txtName;

public JPasswordField pwdPwd;

public JButton btnSub;

public JButton btnReset;

public UserLogIn(){

pnluser = new JPanel();

lbluserLogIn = new JLabel();

lbluserName = new JLabel();

lbluserPWD = new JLabel();

txtName = new JTextField();

pwdPwd = new JPasswordField();

btnSub = new JButton();

btnReset = new JButton();

userInit();

}

public void userInit(){

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置关闭框架的同时结束程序

this.setSize(300,200);//设置框架大小为长300,宽200

this.setResizable(false);//设置框架不可以改变大小

this.setTitle("用户登录");//设置框架标题

this.pnluser.setLayout(null);//设置面板布局管理

this.pnluser.setBackground(Color.cyan);//设置面板背景颜色

this.lbluserLogIn.setText("用户登录");//设置标签标题

this.lbluserLogIn.setFont(new Font("宋体",Font.BOLD | Font.ITALIC,14));//设置标签字体

this.lbluserLogIn.setForeground(Color.RED);//设置标签字体颜色

this.lbluserName.setText("用户名:");

this.lbluserPWD.setText("密 码:");

this.btnSub.setText("登录");

this.btnReset.setText("重置");

this.lbluserLogIn.setBounds(120,15,60,20);//设置标签x坐标120,y坐标15,长60,宽20

this.lbluserName.setBounds(50,55,60,20);

this.lbluserPWD.setBounds(50,85,60,25);

this.txtName.setBounds(110,55,120,20);

this.pwdPwd.setBounds(110,85,120,20);

this.btnSub.setBounds(85,120,60,20);

this.btnSub.addActionListener(new ActionListener()//匿名类实现ActionListener接口

{

public void actionPerformed(ActionEvent e){

btnsub_ActionEvent(e);

}

}

);

this.btnReset.setBounds(155,120,60,20);

this.btnReset.addActionListener(new ActionListener()//匿名类实现ActionListener接口

{

public void actionPerformed(ActionEvent e){

btnreset_ActionEvent(e);

}

}

);

this.pnluser.add(lbluserLogIn);//加载标签到面板

this.pnluser.add(lbluserName);

this.pnluser.add(lbluserPWD);

this.pnluser.add(txtName);

this.pnluser.add(pwdPwd);

this.pnluser.add(btnSub);

this.pnluser.add(btnReset);

this.add(pnluser);//加载面板到框架

this.setVisible(true);//设置框架可显

}

public void btnsub_ActionEvent(ActionEvent e){

String name = txtName.getText();

String pwd = String.valueOf(pwdPwd.getPassword());

if(name.equals("")){

JOptionPane.showMessageDialog(null,"账号不能为空","错误",JOptionPane.ERROR_MESSAGE);

return;

}else if (pwd.equals("")){

JOptionPane.showMessageDialog(null,"密码不能为空","错误",JOptionPane.ERROR_MESSAGE);

return;

}else if(true){

this.dispose();

}else{

JOptionPane.showMessageDialog(null,"账号或密码错误","错误",JOptionPane.ERROR_MESSAGE);

return;

}

}

public void btnreset_ActionEvent(ActionEvent e){

txtName.setText("");

pwdPwd.setText("");

}

public static void main(String[] args){

new UserLogIn();

}

}

登录界面的java代码,分别有教师登录,管理员登录,学生登录,右边是用户名和密码,见图。

分三个包,自己建个包,导进去就ok了,数据库是access的。

package 登录;

import java.awt.EventQueue;

public class Cilent {

private JFrame frame;

private JTextField textField;

private JPasswordField passwordField;

/**

* Launch the application.

*/

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() {

try {

Cilent window = new Cilent();

window.frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

}

/**

* Create the application.

*/

public Cilent() {

initialize();

}

/**

* Initialize the contents of the frame.

*/

private void initialize() {

frame = new JFrame();

frame.setTitle("登陆界面");

frame.setBounds(100, 100, 450, 300);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().setLayout(null);

frame.setResizable(false);

JLabel lblNewLabel = new JLabel("用户名");

lblNewLabel.setBounds(38, 43, 80, 34);

frame.getContentPane().add(lblNewLabel);

textField = new JTextField();

textField.setBounds(155, 42, 227, 37);

frame.getContentPane().add(textField);

textField.setColumns(10);

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

label.setBounds(38, 115, 80, 34);

frame.getContentPane().add(label);

passwordField = new JPasswordField();

passwordField.setBounds(155, 115, 227, 37);

frame.getContentPane().add(passwordField);

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

btnNewButton.setBounds(60, 187, 115, 34);

frame.getContentPane().add(btnNewButton);

btnNewButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent arg0) {

// TODO Auto-generated method stub

UserCheck UC=new UserCheck(textField.getText(),String.valueOf(passwordField.getPassword()));

if(UC.getI()!=0) //有此用户

{

frame.setVisible(false);

}

else

{

textField.setText("");

passwordField.setText("");

}

}

});

JButton button = new JButton("取 消");

button.setBounds(242, 187, 115, 34);

frame.getContentPane().add(button);

button.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent arg0) {

// TODO Auto-generated method stub

textField.setText("");

passwordField.setText("");

}

});

}

}

/*****************************************************************/

package 登录;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import 操作处理.UsersCL;

/**@author 20111024

* 检测登录的用户在数据库中有无,若没有,则提示没有此用户,

* 若有,则判断级别:普通用户还是管理员。

*/

public class UserCheck {

private int i=0; //用户级别:0不是用户、1是管理员、2是普通用户

UserCheck(String name ,String password)

{

String jdriver="sun.jdbc.odbc.JdbcOdbcDriver";

String connectDB="jdbc:odbc:Students";

Statement stmt=null;

ResultSet rs=null;

Connection con=null;

try {

Class.forName(jdriver);

con=DriverManager.getConnection(connectDB);

stmt=con.createStatement();

String query="select * from users where name='"+name+"' and passwd='"+password+"'";

rs=stmt.executeQuery(query);

if(rs.next())

{

//数据库中有此用户,访问成功

i=Integer.parseInt(rs.getString(3));

UsersCL UL=new UsersCL(i);

}

else

{

i=0; //没有用户是默认是0级

}

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

public int getI() {

return i;

}

}

/********************************************************************************************/

package 操作处理;

import java.awt.EventQueue;

public class UsersCL implements ActionListener{

private JFrame frame;

private JTextField textField;

private JTextField textField_1;

private JTextField textField_2;

private JTextField textField_3;

private int i=0;

private JLabel label_3;

private JTextField textField_4;

public UsersCL(int i) {

this.i=i;

frame = new JFrame();

frame.setTitle("用户处理界面");

frame.setBounds(100, 100, 450, 300);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().setLayout(null);

frame.setResizable(false);

frame.setVisible(true);

JLabel lblNewLabel = new JLabel("学 号");

lblNewLabel.setBounds(24, 32, 74, 29);

frame.getContentPane().add(lblNewLabel);

JLabel label = new JLabel("姓 名");

label.setBounds(24, 71, 74, 29);

frame.getContentPane().add(label);

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

label_1.setBounds(24, 110, 74, 29);

frame.getContentPane().add(label_1);

label_3 = new JLabel("性 别");

label_3.setBounds(24, 149, 74, 29);

frame.getContentPane().add(label_3);

JLabel label_2 = new JLabel("状 态");

label_2.setBounds(24, 195, 74, 29);

frame.getContentPane().add(label_2);

textField = new JTextField();

textField.setBounds(101, 34, 113, 25);

frame.getContentPane().add(textField);

textField.setColumns(10);

textField_1 = new JTextField();

textField_1.setColumns(10);

textField_1.setBounds(101, 73, 113, 25);

frame.getContentPane().add(textField_1);

textField_2 = new JTextField();

textField_2.setColumns(10);

textField_2.setBounds(101, 112, 113, 25);

frame.getContentPane().add(textField_2);

textField_3 = new JTextField();

textField_3.setEditable(false);

textField_3.setColumns(10);

textField_3.setBounds(101, 199, 288, 25);

frame.getContentPane().add(textField_3);

textField_4 = new JTextField();

textField_4.setColumns(10);

textField_4.setBounds(101, 149, 113, 25);

frame.getContentPane().add(textField_4);

if(1==i)

{

JButton btnNewButton = new JButton("追 加");

btnNewButton.setBounds(276, 41, 113, 29);

frame.getContentPane().add(btnNewButton);

btnNewButton.addActionListener(this);

btnNewButton.setActionCommand("追加");

JButton button_1 = new JButton("删 除");

button_1.setBounds(276, 145, 113, 29);

frame.getContentPane().add(button_1);

button_1.addActionListener(this);

button_1.setActionCommand("删除");

}

JButton button = new JButton("查 询");

button.setBounds(276, 91, 113, 29);

frame.getContentPane().add(button);

button.addActionListener(this);

button.setActionCommand("查询");

}

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

String name,age,sex,query=null;

int num,age1,count=0;

num=Integer.parseInt(textField.getText());

name=textField_1.getText();

age1=Integer.parseInt(textField_2.getText());

sex=textField_4.getText();

if(e.getActionCommand().equals("追加"))

{

query="insert into students values("+num+","+"'"+name+"',"+age1+",'"+sex+"');";

count=1;

}

else if(e.getActionCommand().equals("查询"))

{

query="select * from students where XSB="+num+";";

count=2;

}

else if(e.getActionCommand().equals("删除"))

{

query="delete from students where XSB="+num+" and name="+"'"+name+"'";

count=3;

}

Statement stmt=null;

ResultSet rs=null;

Connection con=null;

String jdriver="sun.jdbc.odbc.JdbcOdbcDriver";

String connectDB="jdbc:odbc:Students";

String query1=null;

try {

Class.forName(jdriver);

con=DriverManager.getConnection(connectDB);

stmt=con.createStatement();

if(count==1)

{

query1="select * from students where XSB="+num+";";

rs=stmt.executeQuery(query1);

if(rs.next())

textField_3.setText("已经由此记录,不能追加!");

else

{

stmt.executeUpdate(query);

textField_3.setText("已经追加完成!");

}

}

else if(2==count)

{

stmt.executeQuery(query);

rs=stmt.executeQuery(query);

if(rs.next())

{

textField_3.setText("已查找到此记录!");

}

else

{

textField_3.setText("没有此记录,可以追加!");

}

}

else if(3==count)

{

query1="select * from students where XSB="+num+" and name="+"'"+name+"'";

rs=stmt.executeQuery(query1);

if(rs.next())

{

stmt.executeUpdate(query);

textField_3.setText("已删除此记录!");

}

else

textField_3.setText("无此记录!");

}

} catch (ClassNotFoundException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

} catch (SQLException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

finally{

//关闭资源

if(stmt!=null){

try {

stmt.close();

} catch (Exception e2) {

// TODO: handle exception

}

stmt=null;

}

if(con!=null){

try {

con.close();

} catch (Exception e2) {

// TODO: handle exception

}

con=null;

}

}

}

}

关于java登陆界面源代码和java登入界面代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/9592.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载