Compare commits
5 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
36803b711c | 2 years ago |
|
|
2ca0e08da7 | 2 years ago |
|
|
47b96ccf73 | 2 years ago |
|
|
188efaeb6e | 2 years ago |
|
|
d40341b2e6 | 2 years ago |
@ -0,0 +1,33 @@
|
||||
package com.wjr.dao.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
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{
|
||||
InputStream input = JDBCUtil.class.getClassLoader()
|
||||
.getResourceAsStream("config.properties");
|
||||
try {
|
||||
info.load(input);
|
||||
url = info.getProperty("url");
|
||||
|
||||
|
||||
Class.forName(info.getProperty("driver"));
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public static Connection getConnection() throws SQLException {
|
||||
Connection conn = DriverManager.getConnection(url,info);
|
||||
return conn;
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,94 @@
|
||||
package com.wjr.view;
|
||||
|
||||
import java.awt.Font;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPasswordField;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
import com.wjr.dao.impl.AccounttmjImpl;
|
||||
import com.wjr.javaBean.Accounttmj;
|
||||
|
||||
public class LoginFrame extends MyFrame{
|
||||
|
||||
|
||||
|
||||
private JTextField txtAccountId;
|
||||
private JPasswordField txtPassword;
|
||||
|
||||
|
||||
|
||||
|
||||
public LoginFrame(String title, int width, int heigth) {
|
||||
super(title, width, heigth);
|
||||
|
||||
getContentPane().setLayout(null);
|
||||
|
||||
JLabel accountLabel=new JLabel();
|
||||
accountLabel.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
accountLabel.setBounds(51,33,83,30);
|
||||
accountLabel.setText("用户名");
|
||||
accountLabel.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
getContentPane().add(accountLabel);
|
||||
|
||||
txtAccountId =new JTextField(10);
|
||||
txtAccountId.setText("root");
|
||||
txtAccountId.setBounds(158,33,157,30);
|
||||
txtAccountId.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
getContentPane().add(txtAccountId);
|
||||
|
||||
JLabel passwordLabel=new JLabel();
|
||||
passwordLabel.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
passwordLabel.setBounds(51,66,83,30);
|
||||
passwordLabel.setText("密码");
|
||||
passwordLabel.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
getContentPane().add(passwordLabel);
|
||||
|
||||
txtPassword =new JPasswordField(10);
|
||||
txtPassword.setText("*****");
|
||||
txtPassword.setBounds(158,66,157,30);
|
||||
txtPassword.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
getContentPane().add(txtPassword);
|
||||
|
||||
|
||||
JButton btnlogin = new JButton();
|
||||
btnlogin.setText("登录");
|
||||
btnlogin.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
btnlogin.setBounds(61,140,100,30);
|
||||
getContentPane().add(btnlogin);
|
||||
|
||||
JButton btnCancel = new JButton();
|
||||
btnCancel.setText("取消");
|
||||
btnCancel.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
btnCancel.setBounds(225,140,100,30);
|
||||
getContentPane().add(btnCancel);
|
||||
|
||||
|
||||
btnlogin.addActionListener(e->{
|
||||
AccounttmjImpl acd = new AccounttmjImpl();
|
||||
Accounttmj actmj = acd.findByUseridtmj(txtAccountId.getText());
|
||||
String password =new String(txtPassword.getPassword());
|
||||
|
||||
if(actmj != null&& password.equals(actmj.getpasswordtmj())) {
|
||||
System.out.println("成功");
|
||||
MovieListFrame plf =new MovieListFrame("电影列表",1000,700);
|
||||
plf.setVisible(true);
|
||||
setVisible(false);
|
||||
}else {
|
||||
JLabel lf = new JLabel("错误");
|
||||
lf.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
JOptionPane.showMessageDialog(null, lf,"登陆失败",JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
btnCancel.addActionListener(e->{
|
||||
System.exit(0);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package com.wjr.view;
|
||||
|
||||
public class MainApp {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
LoginFrame loginFrame=new LoginFrame("用户登录",400,255);
|
||||
loginFrame.setVisible(true);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package com.wjr.view;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
|
||||
private double screenWidth=Toolkit.getDefaultToolkit().getScreenSize().getWidth();
|
||||
private double screenHeight=Toolkit.getDefaultToolkit().getScreenSize().getHeight();
|
||||
|
||||
public MyFrame(String title,int width,int heigth) {
|
||||
super(title);
|
||||
|
||||
setSize(width,heigth);
|
||||
int x=(int)(screenWidth-width)/2;
|
||||
int y=(int)(screenHeight-heigth)/2;
|
||||
setLocation(x,y);
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
driver=com.mysql.cj.jdbc.Driver
|
||||
url=jdbc:mysql://localhost:3306/movie?userSSL=false&serverTimezone=Asia/Shanghai
|
||||
user=root
|
||||
password=123456
|
||||
userSSL = false
|
||||
serverTimezone = Asia/Shanghai
|
||||
Loading…
Reference in new issue