📄 b09e6f69e3dc0019176ddc52c573fd24
字号:
package JavaPhoneTeam10;
import java.awt.*;
//import java.awt.event.*;
import java.net.InetAddress;
//import java.net.UnknownHostException;
//import java.sql.*;
import javax.swing.*;
public class Login {
ConnDB myconn;
JFrame frame;
Font font = new Font("楷体", Font.PLAIN, 13);
TextField text1;
TextField text2;
String uid;
public Login() {
myconn = new ConnDB(); //first of all, create an object of ConnDB
}
//main method
public static void main(String[] args) {
new Login().init();
}
public void init() {
//top panel
Panel top = new Panel();
//add image to top panel
ImageCanvas toplogo = new ImageCanvas("img\\top.jpg", 350, 65);
top.add(toplogo);
//middle panel
Panel middle = new Panel();
middle.setLocation(1, 1);
middle.setSize(350, 120);
//prepare JTextFeld
text1 = new TextField();
// text2 = new JTextField();
text2 = new TextField();
text1.setLocation(10, 10);
text1.setFont(font);
text1.setSize(180, 40);
text1.setBackground(new Color(243, 234, 245));
text1.setFont(new Font("楷体", Font.PLAIN, 25));
// text2.setLocation(10, 65);
// text2.setFont(font);
// text2.setSize(180, 40);
// text2.setHorizontalAlignment(JTextField.LEFT);
// text2.setBackground(new Color(243, 234, 245));
// text2.setFont(new Font("楷体", Font.PLAIN, 25));
text2.setLocation(10, 65);
text2.setFont(font);
text2.setSize(180, 40);
text2.setBackground(new Color(243, 234, 245));
text2.setFont(new Font("楷体", Font.PLAIN, 25));
text2.setEchoChar('*');
//text panel
Panel text = new Panel();
text.setSize(200, 120);
text.setLocation(100, 1);
text.setLayout(null);
text.add(text1);
text.add(text2);
//prepare button
JTextField bt1 = new JTextField("用户名");
JTextField bt2 = new JTextField("密 码");
bt1.setEditable(false);
bt1.setSize(50, 30);
bt1.setLocation(10, 13);
bt1.setFont(font);
bt1.setBackground(new Color(200, 200, 200));
bt2.setEditable(false);
bt2.setSize(50, 30);
bt2.setLocation(10, 69);
bt2.setFont(font);
bt2.setBackground(new Color(200, 200, 200));
//button panel
Panel bt = new Panel();
bt.setLocation(5, 10);
bt.setSize(100, 120);
bt.setLayout(null);
bt.add(bt1);
bt.add(bt2);
//add button and textfield to panel
middle.add(text);
middle.add(bt);
//bottom panel
Panel bottom = new Panel();
bottom.setLocation(1, 140);
bottom.setSize(350, 70);
bottom.setLayout(new GridLayout(2, 3, 5, 5));
//prepare order buttuons
JButton[] orderbt = new JButton[6];
orderbt[0] = new JButton("记住密码");
orderbt[1] = new JButton("登录");
orderbt[2] = new JButton("注册");
orderbt[3] = new JButton("取消");
orderbt[4] = new JButton("网络测试");
orderbt[5] = new JButton("忘记密码");
//set bottom and add buttons to panel
for (int i = 0; i < 6; i++) {
orderbt[i].setFont(font);
orderbt[i].setSize(30, 35);
bottom.add(orderbt[i]);
}
orderbt[1].addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
processNumberDial(evt);
}
});
orderbt[2].addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
/* try {
myconn.executeQuery("select * from phone where id='"
+ text1.getText() + "'");
if (!myconn.db_rset.next()) {
try {
myconn
.executeUpdate("insert into phone(id,pwd,address) values('"
+ text1.getText()
+ "','"
+ text2.getText()
+ "','"
+ InetAddress.getLocalHost()
.getHostAddress()
.toString() + "')");
JOptionPane.showConfirmDialog(null, "注册成功!",
"Info", JOptionPane.CLOSED_OPTION,
JOptionPane.INFORMATION_MESSAGE);
} catch (Exception e) {
e.printStackTrace();
}
} else {
JOptionPane.showConfirmDialog(null, "帐号已存在,请新建一个!",
"Info", JOptionPane.CLOSED_OPTION,
JOptionPane.INFORMATION_MESSAGE);
}
} catch (Exception e) {
e.printStackTrace();
}*/
new FirstLogin().init();
frame.dispose();
}
});
orderbt[3].addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
frame.dispose();
}
});
//main
Panel main = new Panel();
main.setLayout(null);
main.add(middle);
main.add(bottom);
// frame
frame = new JFrame("Login copyright@JavaTeam10");
frame.setSize(350, 320);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(top, "North");
frame.getContentPane().add(main);
frame.setVisible(true);
}
private void processNumberDial(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_processNumberDial
uid = text1.getText();
try {
myconn.executeQuery("select * from phone where id='"
+ text1.getText() + "' and pwd='" + text2.getText() + "'");
if (!myconn.db_rset.next()) {
text1.setText("");
text2.setText("");
JOptionPane.showConfirmDialog(null, "incorrect user id!",
"Info", JOptionPane.CLOSED_OPTION,
JOptionPane.INFORMATION_MESSAGE);
} else {
myconn.executeUpdate("update phone set address='"
+ InetAddress.getLocalHost().getHostAddress()
.toString() + "',flag=1 where id='" + uid + "'");
// 如果登录成功,便跳转到JavaPhone,同时关闭Login界面
frame.dispose();
JOptionPane.showConfirmDialog(null, "登录成功!", "Info",
JOptionPane.CLOSED_OPTION,
JOptionPane.INFORMATION_MESSAGE);
new JavaPhone().init();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -