完整的Java视频教程Docker视频免费下载
链接:
提取码:1r9g
Docker视频|走进Docker|从Docker到CaaS(一)Docker集群管理介绍|从Docker到CaaS(三)Kubernetes|从Docker到CaaS(六)微服务与CaaS|从Docker到CaaS(二)Docker 容器管理工具|从 Docker 到 CaaS(五)灵雀云部署 Docker 容器|
java ATM登陆循环代码?下面是一个简单口述java登陆代码视频的登录示例口述java登陆代码视频:
代码复制展示:
public class ATMLogin {
【口述java登陆代码视频 java编写登录程序】public static void main(String[] args) {
// 设置用户名和密码
String username = "gqk";
String password = "520";
// 最多可以登录 3 次
for (int i = 0; i3; i) {
// 读取用户输入的用户名和密码
Scanner in = new Scanner(System.in);
System.out.print("请输入用户名:");
String inputUsername = in.nextLine();
System.out.print("请输入密码:");
String inputPassword = in.nextLine();
// 检查用户名和密码是否正确
if (inputUsername.equals(username)inputPassword.equals(password)) {
System.out.println("欢迎"username"登录!");
break; // 登录成功口述java登陆代码视频,退出循环
} else {
System.out.println("用户名或密码错误口述java登陆代码视频,请重新输入!");
}
}
// 如果 3 次登录都失败,则提示用户
System.out.println("卡片已经被锁 , 请联系客服人员!");
}
}
回答不易望请采纳
如何用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代码,分别有教师登录,管理员登录,学生登录,右边是用户名和密码 , 见图 。分三个包,自己建个包,导进去就ok口述java登陆代码视频了 , 数据库是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
* 检测登录的用户在数据库中有无 , 若没有,则提示没有此用户,
* 若有,则判断级别口述java登陆代码视频:普通用户还是管理员 。
*/
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("已经由此记录,不能追加口述java登陆代码视频!");
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编写登录程序的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。
推荐阅读
- 新赛季视频号直播视频,视频号直播比赛
- 关于postgresql数据容量设定的信息
- 学下载,瑞幸大学下载
- u盘插有什么作用,u盘应该插哪个孔
- php向js发送数据类型 php给js传值
- oracle查询第几周,oracle获取第几周
- 关于wps的ppt怎么插入视频的信息
- 战略游戏swicth,战略游戏破解版
- 菜鸟教程php数据库技术 菜鸟教程 mysql