
正文
java围棋代码用户登录 js围棋
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
用java类模拟游戏的账号的登陆,注册,退出。 1.没有账号,需要注册。 2.注册完成后方可登
/**
需求:奖客富翁游戏。
菜单为:
1.注册用户信息。填写用户名,密码,电脑随机输出一个4位
数字作为会员卡号。提示用户名,密码,及会员卡号。可选择第二步了
2.登陆。校验是否已注册(是否存在会员卡号)。如果为空,
提示用户不存在。
如果用户名通过,密码错误,提示用户名和密码不匹配。如果
验证成功结束。如果输入的用户名密码均匹配,给出登陆成功提示。
可选择第三步了。
3.先判断用户是否已登陆(是否存在会员卡)
询问是否进行抽奖,选Y,电脑随机输出5个4位
数字。如果其中有一个数字与用户卡号相同,则为中奖,奖励
人民币为卡号数字的金额。否则,谢谢参与。程序退出。
*/
import java.util.Scanner;
import java.util.Random;
public class RichPerson {
public static void main(String[] args) {
// 输出菜单。
for (int a = 0; a 6; a++) {
System.out.print("*");
}
System.out.print("欢迎进入奖客富翁系统");
for (int b = 0; b 6; b++) {
System.out.print("*");
}
System.out.print("\n\t\t1.注册\n" + "\t\t2.登录\n" + "\t\t3.抽奖\n");
for (int c = 0; c 31; c++) {
System.out.print("*");
}
// 输出菜单结束。
int caidan = 0;// 操作菜单
String name = null;// 会员注册名字
String myname = null;// 会员登录名字
String password = null;// 会员注册密码
String mypassword = null;// 会员登录密码
int number = 0;// 会员卡号
// int luckynumber=0;//幸运号码
String str = null;// 询问是否重试
// 输入数字选择菜单。
Scanner input = new Scanner(System.in);
Random output = new Random();
do {
System.out.println("\n请选择菜单:");
caidan = input.nextInt();
switch (caidan) {
case 1:
System.out.println("欢迎注册富翁,请依次输入用户名和密码");
System.out.println("用户名:");
name = input.next();
System.out.println("密码:");
password = input.next();
// 随机给出4位数的会员卡号
number = output.nextInt(8999) + 1000;
System.out.println("注册成功!您的用户名:" + name + ",密码:" + password
+ ",会员卡号:" + number + "。请牢记!");
break;
case 2:
// 先判断用户是否已注册。
if (name == null) {
System.out.println("您好,请先注册!");
break;
} else {
System.out.println("欢迎登录富翁,请依次输入用户名和密码!");
// 用户名和密码匹配校验次数设置为3次。
for (int x = 0; x 3; x++) {
System.out.println("用户名:");
myname = input.next();
if (!myname.equals(name)) {
System.out.println("用户" + myname + "不存在!请重试,剩余次数"
+ (2 - x) + "次!");
} else {
System.out.println("密码:");
}
mypassword = input.next();
if (!mypassword.equals(password)) {
System.out.println(myname + "密码错误!" + "请重试,剩余次数"
+ (2 - x) + "次!");
} else {
System.out.println("登陆成功!");
break;
}
}
}
break;
case 3:
// 判断用户是否已注册,是否已登录。
if (mypassword == null) {
System.out.println("您好,请先登录!");
break;
} else if (!mypassword.equals(password)) {
System.out.println("您好,请先重试登录!");
break;
} else if (mypassword.equals(password)) {
System.out.println("欢迎进入富翁,请问是否进行幸运抽奖(y/n)?");
String choujiang = input.next();
if (choujiang.equals("y")) {
int[] luckynumber = new int[5];
for (int m = 0; m 5; m++) {
luckynumber[m] = output.nextInt(8999) + 1000;
}
for (int m = 0; m 5; m++) {
System.out.print(luckynumber[m] + "\t");
}
System.out.println("\n" + number);
for (int m = 0; m 5; m++) {
if (number == luckynumber[m]) {
System.out.println("\n中奖!金额为:" + luckynumber);
break;
} else {
System.out.println("\n木有中奖!");
break;
}
}
} else {
System.out.println("程序结束!");
break;
}
}
break;
default:
System.out.println("没有对应的菜单选项!请重试");
break;
}
System.out.println("是否继续(y/n)?");
str = input.next();
} while (str.equals("y"));
System.out.println("程序结束!");
}
}
给个代码 自己玩玩
相关问答
Q1: 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
Q2: 用JAVA编一个用户登录界面,用户必须输入账号密码才能进入
简单代码如下,原本想用弹窗的,懒得写了:
import java.awt.Container;
import java.awt.FlowLayout;
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.JTextField;
public class dengru extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
private Container c = null;
private JButton jb = null;
public dengru() {
this.setLayout(new FlowLayout());
jb = new JButton("登入");
jb.addActionListener(this);
this.add(jb);
this.setSize(500, 400);
this.setVisible(true);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
public static void main(String[] args) {
new dengru();
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jb) {
JFrame jf=new JFrame();
c = jf.getContentPane();
c.setLayout(new GridLayout(3,2,2,2));
JLabel jl1 = new JLabel("用户名:");
JLabel jl2 = new JLabel("密 码:");
JTextField jtf1 = new JTextField();
JTextField jtf2 = new JTextField();
jtf1.setSize(200, 40);
jtf2.setSize(200, 40);
c.add(jl1);
c.add(jtf1);
c.add(jl2);
c.add(jtf2);
c.add(new JButton("登入"));
jf.setVisible(true);
jf.setSize(300, 100);
jf.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
}
}
Q3: 求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围棋代码用户登录和js围棋的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







