Compare commits
No commits in common. 'main' and 'zhuce' have entirely different histories.
@ -1,2 +0,0 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
@ -1,14 +0,0 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=17
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=17
|
||||
@ -1,29 +0,0 @@
|
||||
package JDBC;
|
||||
import java.io.InputStream;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
public class JDBCUtil {
|
||||
static String url;
|
||||
static Properties info = new Properties();
|
||||
static{
|
||||
try {
|
||||
InputStream in=JDBCUtil.class.getClassLoader().getResourceAsStream("config.properties");
|
||||
info.load(in);
|
||||
url=info.getProperty("url");
|
||||
Class.forName(info.getProperty("driver"));
|
||||
} catch (Exception e) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Connection getConnertion() throws SQLException{
|
||||
Connection conn =DriverManager.getConnection(url,info.getProperty("user"),info.getProperty("password"));
|
||||
return conn;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
driver=com.mysql.cj.jdbc.Driver
|
||||
url=jdbc:mysql://localhost:3306/gold?userSSL=flase&serverTimezone=Asia/Shanghai
|
||||
user=root
|
||||
password=asdasd123
|
||||
userSSL=flase
|
||||
serverTimezone=Asia/Shanghai
|
||||
|
Before Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 7.2 KiB |
|
Before Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 9.9 KiB |
|
Before Width: | Height: | Size: 9.7 KiB |
|
Before Width: | Height: | Size: 4.1 KiB |
@ -1,13 +0,0 @@
|
||||
package com.Drj.Object;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
|
||||
public class GoldMinidrj extends Golddrj{
|
||||
public GoldMinidrj() {
|
||||
this.width=36;
|
||||
this.height =36;//由于图片大小不同重新设置一个宽高
|
||||
this.m=15;//由于质量大小不同重新设置一个质量
|
||||
this.count=2;//设置积分
|
||||
this.img =Toolkit.getDefaultToolkit().getImage("image/gold0.gif");//由于图片不同重新设置一个路径
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
package com.Drj.Object;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
|
||||
public class GoldPlusdrj extends Golddrj{
|
||||
public GoldPlusdrj() {
|
||||
//由于大金矿过大会溢出画面重新设置其坐标
|
||||
this.x=(int)(Math.random()*650);//金矿x轴随机位置的函数
|
||||
this.y=(int)(Math.random()*550+300);//金矿y轴随机位置的函数
|
||||
this.width=105;
|
||||
this.height =105;//由于图片大小不同重新设置一个宽高
|
||||
this.m=60;//由于质量大小不同重新设置一个质量
|
||||
this.count=8;//设置积分
|
||||
this.img =Toolkit.getDefaultToolkit().getImage("image/gold2.gif");//由于图片不同重新设置一个路径
|
||||
}
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
package com.Drj.Object;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
|
||||
public class Golddrj extends Objectdrj{
|
||||
boolean f=false;//用于判断是否被抓取
|
||||
public Golddrj() {
|
||||
this.x=(int)(Math.random()*700);//金矿x轴随机位置的函数
|
||||
this.y=(int)(Math.random()*550+300);//金矿y轴随机位置的函数
|
||||
this.width=52;//设置宽
|
||||
this.height =52;//设置高
|
||||
this.f=false;
|
||||
this.m=30;//设置质量
|
||||
this.count=4;//设置积分
|
||||
this.type=1;
|
||||
this.img =Toolkit.getDefaultToolkit().getImage("image/gold1.gif");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
package com.Drj.Object;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
|
||||
public class Rockdrj extends Objectdrj{
|
||||
boolean f=false;//用于判断是否被抓取
|
||||
public Rockdrj() {
|
||||
this.x=(int)(Math.random()*700);//石头x轴随机位置的函数
|
||||
this.y=(int)(Math.random()*550+300);//石头y轴随机位置的函数
|
||||
this.width=71;
|
||||
this.height =71;
|
||||
this.f=false;
|
||||
this.m=50;
|
||||
this.count=1;//设置积分
|
||||
this.type=2;
|
||||
this.img =Toolkit.getDefaultToolkit().getImage("image/rock1.png");
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
package com.Drj.shop;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import com.Drj.Bg.Bgdrj;
|
||||
import com.Drj.gameWin.gameWindrj;
|
||||
public class Shopdrj {
|
||||
public void mouseClicked(MouseEvent e,Bgdrj bg) {
|
||||
if(e.getButton()==1) {
|
||||
bg.shop=true;
|
||||
}
|
||||
if(e.getButton()==3) {
|
||||
gameWindrj.state=1;
|
||||
bg.startTime=System.currentTimeMillis();//给开始时间赋值为系统时间
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,137 +0,0 @@
|
||||
package com.Lhy.login;
|
||||
import javax.swing.*;
|
||||
|
||||
import com.Zsn.zhuce.Zhuce;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
|
||||
public class Login extends JFrame implements ActionListener,MouseListener {
|
||||
public boolean flagdl=false;
|
||||
public static String name;
|
||||
private JTextField usernameText;
|
||||
private JPasswordField passwordText;
|
||||
private JButton loginButton;
|
||||
private JButton cancelButton;
|
||||
private JButton zhuceButton;
|
||||
private JLabel usernameLabel;
|
||||
private JLabel passwordLabel;
|
||||
public Login() {
|
||||
this.setSize(768,1000);
|
||||
this.setUndecorated(true);
|
||||
this.setLocationRelativeTo(null);
|
||||
usernameLabel = new JLabel("用户:");
|
||||
usernameLabel.setBounds(250, 300, 90, 35);
|
||||
usernameLabel.setForeground(Color.white);
|
||||
usernameLabel.setFont(new Font("微软雅黑", Font.PLAIN, 18));
|
||||
this.add(usernameLabel);
|
||||
usernameText = new JTextField();
|
||||
usernameText.setBounds(350, 300, 150, 35);
|
||||
usernameText.setFont(new Font("微软雅黑",Font.PLAIN,16));
|
||||
usernameText.setOpaque(false);
|
||||
usernameText.setBorder(null);
|
||||
usernameText.addMouseListener(this);
|
||||
this.add(usernameText);
|
||||
passwordLabel = new JLabel("密码:");
|
||||
passwordLabel.setBounds(250, 400, 90, 35);
|
||||
passwordLabel.setForeground(Color.white);
|
||||
passwordLabel.setFont(new Font("微软雅黑", Font.PLAIN, 18));
|
||||
this.add(passwordLabel);
|
||||
passwordText = new JPasswordField();
|
||||
passwordText.setBounds(350, 400, 150, 35);
|
||||
passwordText.setOpaque(false);
|
||||
passwordText.setBorder(null);
|
||||
passwordText.addMouseListener(this);
|
||||
this.add(passwordText);
|
||||
loginButton = new JButton("登陆");
|
||||
loginButton.setFont(new Font("微软雅黑",Font.PLAIN,18));
|
||||
loginButton.setBounds(300, 500, 100, 35);
|
||||
loginButton.setForeground(Color.white);
|
||||
loginButton.setOpaque(false);
|
||||
loginButton.setContentAreaFilled(false);
|
||||
this.add(loginButton);
|
||||
loginButton.addActionListener(this);
|
||||
cancelButton = new JButton("退出");
|
||||
cancelButton.setFont(new Font("微软雅黑",Font.PLAIN,18));
|
||||
cancelButton.setBounds(450, 500, 100, 35);
|
||||
cancelButton.setOpaque(false);
|
||||
cancelButton.setContentAreaFilled(false);
|
||||
cancelButton.setForeground(Color.white);
|
||||
this.add(cancelButton);
|
||||
cancelButton.addActionListener(this);
|
||||
loginButton.addActionListener(this);
|
||||
zhuceButton= new JButton("注册");
|
||||
zhuceButton.setFont(new Font("微软雅黑",Font.PLAIN,18));
|
||||
zhuceButton.setBounds(375, 600, 100, 35);
|
||||
zhuceButton.setOpaque(false);
|
||||
zhuceButton.setContentAreaFilled(false);
|
||||
zhuceButton.setForeground(Color.white);
|
||||
this.add(zhuceButton);
|
||||
zhuceButton.addActionListener(this);
|
||||
Loginbg a= new Loginbg();
|
||||
this.add(a);
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public void setName(String name) {
|
||||
Login.name = name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e){
|
||||
if (e.getSource() == cancelButton) {
|
||||
JOptionPane.showMessageDialog(this, "欢迎下次游玩");
|
||||
System.exit(0);
|
||||
}
|
||||
if (e.getSource() == loginButton) {
|
||||
name = usernameText.getText().trim();
|
||||
char[] password = passwordText.getPassword();
|
||||
String pass=String.valueOf(password);
|
||||
boolean a=LoginImpl.check(name,pass);
|
||||
if(a) {
|
||||
JOptionPane.showMessageDialog(this, "登录成功!");
|
||||
this.flagdl=true;
|
||||
this.setVisible(false);
|
||||
}else {
|
||||
JOptionPane.showMessageDialog(this, "输入错误,请重新输入");
|
||||
usernameText.setText("");
|
||||
passwordText.setText("");
|
||||
}
|
||||
}
|
||||
if(e.getSource() == zhuceButton) {
|
||||
Zhuce z=new Zhuce();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
package com.Lhy.login;
|
||||
|
||||
public interface LoginDao {
|
||||
public static boolean check(String username,String password) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
package com.Lhy.login;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import JDBC.JDBCUtil;
|
||||
|
||||
public class LoginImpl implements LoginDao{
|
||||
public static boolean check(String username,String password) {
|
||||
// TODO 自动生成的方法存根
|
||||
boolean flaguser=false;
|
||||
try {
|
||||
Connection conn =JDBCUtil.getConnertion();
|
||||
String sql ="select *from user where username=? and password=?";
|
||||
PreparedStatement prestm=conn.prepareStatement(sql);
|
||||
prestm.setString(1,username);
|
||||
prestm.setString(2,password);
|
||||
ResultSet rs=prestm.executeQuery();
|
||||
if(rs.next()) {
|
||||
flaguser=true;
|
||||
}
|
||||
rs.close();
|
||||
prestm.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return flaguser;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
package com.Lhy.login;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class Loginbg extends JPanel {
|
||||
private Image bg =Toolkit.getDefaultToolkit().getImage("image/bg.jpg");
|
||||
private Image tk =Toolkit.getDefaultToolkit().getImage("image/tk.jpg");
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
g.drawImage(tk,0,0,null);
|
||||
g.drawImage(bg,0,200,null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,25 +0,0 @@
|
||||
package com.Lhy.login;
|
||||
|
||||
public class User{
|
||||
String username;
|
||||
String password;
|
||||
public User() {}
|
||||
public User(String username, String password) {
|
||||
super();
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>phb</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@ -1,33 +0,0 @@
|
||||
package com.Sq.phb;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.Drj.gameWin.gameWindrj;
|
||||
|
||||
public class Phb {
|
||||
public void paint(Graphics g,int count) {
|
||||
word(g,30,Color.red,"游戏失败",300,100);
|
||||
word(g,30,Color.BLACK,"排行榜",325,130);
|
||||
if(!PhbImpl.check(gameWindrj.username,count)) {
|
||||
System.out.print(PhbImpl.insert(gameWindrj.username,count));
|
||||
}
|
||||
ArrayList<UserScore> us=PhbImpl.orderBy();
|
||||
int i=0;
|
||||
for(UserScore a:us) {
|
||||
if(i==10)break;
|
||||
word(g,60,Color.BLACK,"第"+(i+1)+"名用户"+a.username+"的积分为"+a.score,50,190+i*60);
|
||||
i++;
|
||||
}
|
||||
word(g,50,Color.red,"点击左键重新开始游戏",100,800);
|
||||
//打印积分
|
||||
word(g,20,Color.red,"此次积分"+count,350,750);
|
||||
}
|
||||
public static void word(Graphics g,int size,Color color,String str,int x,int y) {
|
||||
g.setColor(color);//设置积分颜色
|
||||
g.setFont(new Font("仿宋",Font.BOLD,size));//设置字体和大小
|
||||
g.drawString(str, x, y);//设置输出格式和位置
|
||||
}
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
package com.Sq.phb;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface PhbDao {
|
||||
public static boolean insert(String username,int score) {
|
||||
return false;
|
||||
}
|
||||
public static boolean check(String username,int score) {
|
||||
return false;
|
||||
}
|
||||
public static ArrayList<UserScore> orderBy() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1,73 +0,0 @@
|
||||
package com.Sq.phb;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import JDBC.JDBCUtil;
|
||||
import com.Lhy.login.LoginDao;
|
||||
|
||||
|
||||
public class PhbImpl implements PhbDao{
|
||||
public static boolean insert(String username,int score) {
|
||||
boolean flaguser=false;
|
||||
try {
|
||||
Connection conn =JDBCUtil.getConnertion();
|
||||
String sql ="Insert into score (username,score) values(?,?)";
|
||||
PreparedStatement prestm=conn.prepareStatement(sql);
|
||||
prestm.setString(1,username);
|
||||
prestm.setLong(2,score);
|
||||
if(prestm.executeUpdate()!=0) {
|
||||
flaguser=true;
|
||||
}
|
||||
prestm.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return flaguser;
|
||||
}
|
||||
public static boolean check(String username,int score) {
|
||||
// TODO 自动生成的方法存根
|
||||
boolean flaguser=false;
|
||||
try {
|
||||
Connection conn =JDBCUtil.getConnertion();
|
||||
String sql ="select *from score where username=? and score=?";
|
||||
PreparedStatement prestm=conn.prepareStatement(sql);
|
||||
prestm.setString(1,username);
|
||||
prestm.setLong(2,score);
|
||||
ResultSet rs=prestm.executeQuery();
|
||||
if(rs.next()) {
|
||||
flaguser=true;
|
||||
}
|
||||
rs.close();
|
||||
prestm.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return flaguser;
|
||||
}
|
||||
public static ArrayList<UserScore> orderBy() {
|
||||
ArrayList<UserScore> us=new ArrayList<UserScore>();
|
||||
try {
|
||||
Connection conn =JDBCUtil.getConnertion();
|
||||
String sql = "select *from score order by score desc";
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql);
|
||||
ResultSet rs=pstmt.executeQuery();
|
||||
while(rs.next()) {
|
||||
UserScore score=new UserScore();
|
||||
score.setUsername(rs.getString("username"));
|
||||
score.setScore(rs.getInt("score"));
|
||||
us.add(score);
|
||||
}
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return us;
|
||||
}
|
||||
}
|
||||
@ -1,33 +0,0 @@
|
||||
package com.Sq.phb;
|
||||
|
||||
public class UserScore {
|
||||
String username;
|
||||
int score;
|
||||
public UserScore() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param username
|
||||
* @param score
|
||||
*/
|
||||
public UserScore(String username,int score) {
|
||||
super();
|
||||
this.username = username;
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
public int getScore() {
|
||||
return score;
|
||||
}
|
||||
public void setScore(int score) {
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Zsn</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@ -1,25 +0,0 @@
|
||||
package com.Zsn.zhuce;
|
||||
|
||||
public class User{
|
||||
String username;
|
||||
String password;
|
||||
public User() {}
|
||||
public User(String username, String password) {
|
||||
super();
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,135 +0,0 @@
|
||||
package com.Zsn.zhuce;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPasswordField;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import com.Lhy.login.Login;
|
||||
|
||||
public class Zhuce extends JFrame implements ActionListener,MouseListener {
|
||||
private JTextField usernameText;
|
||||
private JPasswordField passwordText;
|
||||
private JButton zhuceButton1;
|
||||
private JButton cancelButton;
|
||||
private JLabel usernameLabel;
|
||||
private JLabel passwordLabel;
|
||||
public Zhuce() {
|
||||
this.setSize(768,1000);
|
||||
this.setUndecorated(true);
|
||||
this.setLocationRelativeTo(null);
|
||||
usernameLabel = new JLabel("用户:");
|
||||
usernameLabel.setBounds(250, 300, 90, 35);
|
||||
usernameLabel.setForeground(Color.white);
|
||||
usernameLabel.setFont(new Font("微软雅黑", Font.PLAIN, 18));
|
||||
this.add(usernameLabel);
|
||||
usernameText = new JTextField();
|
||||
usernameText.setBounds(350, 300, 150, 35);
|
||||
usernameText.setFont(new Font("微软雅黑",Font.PLAIN,16));
|
||||
usernameText.setOpaque(false);
|
||||
usernameText.setBorder(null);
|
||||
usernameText.addMouseListener(this);
|
||||
this.add(usernameText);
|
||||
passwordLabel = new JLabel("密码:");
|
||||
passwordLabel.setBounds(250, 400, 90, 35);
|
||||
passwordLabel.setForeground(Color.white);
|
||||
passwordLabel.setFont(new Font("微软雅黑", Font.PLAIN, 18));
|
||||
this.add(passwordLabel);
|
||||
passwordText = new JPasswordField();
|
||||
passwordText.setBounds(350, 400, 150, 35);
|
||||
passwordText.setOpaque(false);
|
||||
passwordText.setBorder(null);
|
||||
passwordText.addMouseListener(this);
|
||||
this.add(passwordText);
|
||||
zhuceButton1 = new JButton("注册");
|
||||
zhuceButton1.setFont(new Font("微软雅黑",Font.PLAIN,18));
|
||||
zhuceButton1.setBounds(300, 500, 100, 35);
|
||||
zhuceButton1.setForeground(Color.white);
|
||||
zhuceButton1.setOpaque(false);
|
||||
zhuceButton1.setContentAreaFilled(false);
|
||||
this.add(zhuceButton1);
|
||||
zhuceButton1.addActionListener(this);
|
||||
cancelButton = new JButton("返回");
|
||||
cancelButton.setFont(new Font("微软雅黑",Font.PLAIN,18));
|
||||
cancelButton.setBounds(450, 500, 100, 35);
|
||||
cancelButton.setOpaque(false);
|
||||
cancelButton.setContentAreaFilled(false);
|
||||
cancelButton.setForeground(Color.white);
|
||||
this.add(cancelButton);
|
||||
cancelButton.addActionListener(this);
|
||||
zhuceButton1.addActionListener(this);
|
||||
Zhucebg a=new Zhucebg();
|
||||
this.add(a);
|
||||
this.setVisible(true);
|
||||
}
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
// TODO 自动生成的方法存根
|
||||
|
||||
}
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
// TODO 自动生成的方法存根
|
||||
|
||||
}
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
// TODO 自动生成的方法存根
|
||||
|
||||
}
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
// TODO 自动生成的方法存根
|
||||
if(e.getSource()==usernameText)
|
||||
{
|
||||
usernameText.setBorder(BorderFactory.createLineBorder(new Color(0,0,0)));
|
||||
}else if(e.getSource()==passwordText)
|
||||
{
|
||||
passwordText.setBorder(BorderFactory.createLineBorder(new Color(0,0,0)));
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
if(e.getSource()==usernameText)
|
||||
{
|
||||
usernameText.setBorder(null);
|
||||
}else if(e.getSource()==passwordText)
|
||||
{
|
||||
passwordText.setBorder(null);
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO 自动生成的方法存根
|
||||
if (e.getSource() == cancelButton) {
|
||||
this.setVisible(false);
|
||||
}
|
||||
else if (e.getSource() == zhuceButton1) {
|
||||
String name = usernameText.getText().trim();
|
||||
char[] password = passwordText.getPassword();
|
||||
String pass=String.valueOf(password);
|
||||
boolean b=ZhuceImpl.check(name);
|
||||
boolean a=ZhuceImpl.insert(name,pass);
|
||||
if(a&!b) {
|
||||
JOptionPane.showMessageDialog(this, "注册成功!");
|
||||
this.setVisible(false);
|
||||
}else {
|
||||
JOptionPane.showMessageDialog(this, "账户已有,请重新输入");
|
||||
usernameText.setText("");
|
||||
passwordText.setText("");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
package com.Zsn.zhuce;
|
||||
|
||||
public interface ZhuceDao {
|
||||
public static boolean insert(String username,String password) {
|
||||
return false;
|
||||
}
|
||||
public static boolean check(String username) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1,54 +0,0 @@
|
||||
package com.Zsn.zhuce;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import JDBC.JDBCUtil;
|
||||
|
||||
|
||||
public class ZhuceImpl implements ZhuceDao{
|
||||
public static boolean insert(String username,String password) {
|
||||
// TODO 自动生成的方法存根
|
||||
boolean flaguser=false;
|
||||
try {
|
||||
Connection conn =JDBCUtil.getConnertion();
|
||||
String sql ="Insert into user (username,password) values(?,?)";
|
||||
PreparedStatement prestm=conn.prepareStatement(sql);
|
||||
prestm.setString(1,username);
|
||||
prestm.setString(2,password);
|
||||
if(prestm.executeUpdate()!=0) {
|
||||
flaguser=true;
|
||||
}
|
||||
prestm.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return flaguser;
|
||||
}
|
||||
public static boolean check(String username) {
|
||||
// TODO 自动生成的方法存根
|
||||
boolean flaguser=false;
|
||||
try {
|
||||
Connection conn =JDBCUtil.getConnertion();
|
||||
String sql ="select *from user where username=?";
|
||||
PreparedStatement prestm=conn.prepareStatement(sql);
|
||||
prestm.setString(1,username);
|
||||
ResultSet rs=prestm.executeQuery();
|
||||
if(rs.next()) {
|
||||
flaguser=true;
|
||||
}
|
||||
rs.close();
|
||||
prestm.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return flaguser;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,17 +0,0 @@
|
||||
package com.Zsn.zhuce;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Image;
|
||||
import java.awt.Toolkit;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class Zhucebg extends JPanel {
|
||||
private Image bg =Toolkit.getDefaultToolkit().getImage("image/bg.jpg");
|
||||
private Image tk =Toolkit.getDefaultToolkit().getImage("image/tk.jpg");
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
g.drawImage(tk,0,0,null);
|
||||
g.drawImage(bg,0,200,null);
|
||||
}
|
||||
}
|
||||