📄 f00de48f83de001918c8dcef2a1618d5
字号:
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 FirstLogin {
ConnDB myconn;
JFrame frame;
Font font = new Font("楷体", Font.PLAIN, 13);
TextField text1;
// JTextField text2;
TextField text2;
TextField text3;
String uid;
public FirstLogin() {
myconn = new ConnDB(); //first of all, create an object of ConnDB
}
public static void main(String[] args) {
new FirstLogin().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, 100);
//prepare JTextFeld
text1 = new TextField();
text2 = new TextField();
text3 = new TextField();
text1.setLocation(10, 10);
text1.setFont(font);
text1.setSize(180, 20);
text1.setBackground(new Color(243, 234, 245));
text1.setFont(new Font("楷体", Font.PLAIN, 18));
text2.setLocation(10, 40);
text2.setFont(font);
text2.setSize(180, 20);
text2.setBackground(new Color(243, 234, 245));
text2.setFont(new Font("楷体", Font.PLAIN, 18));
text2.setEchoChar('*');
text3.setLocation(10, 70);
text3.setFont(font);
text3.setSize(180, 20);
text3.setBackground(new Color(243, 234, 245));
text3.setFont(new Font("楷体", Font.PLAIN, 18));
text3.setEchoChar('*');
//text panel
Panel text = new Panel();
text.setSize(200, 100);
text.setLocation(100, 1);
text.setLayout(null);
text.add(text1);
text.add(text2);
text.add(text3);
//prepare button
JTextField bt1 = new JTextField("用 户 名");
JTextField bt2 = new JTextField("密 码");
JTextField bt3 = new JTextField("密码确认");
bt1.setEditable(false);
bt1.setSize(60, 20);
bt1.setLocation(10, 10);
bt1.setFont(font);
bt1.setBackground(new Color(200, 200, 200));
bt2.setEditable(false);
bt2.setSize(60, 20);
bt2.setLocation(10, 40);
bt2.setFont(font);
bt2.setBackground(new Color(200, 200, 200));
bt3.setEditable(false);
bt3.setSize(60, 20);
bt3.setLocation(10, 70);
bt3.setFont(font);
bt3.setBackground(new Color(200, 200, 200));
//button panel
Panel bt = new Panel();
bt.setLocation(5, 10);
bt.setSize(100, 100);
bt.setLayout(null);
bt.add(bt1);
bt.add(bt2);
bt.add(bt3);
//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);
new Login().init();
frame.dispose();
}
});
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() + "')");
new JavaPhone().init();
frame.dispose();
JOptionPane.showConfirmDialog(null, "注册成功!",
"Info", JOptionPane.CLOSED_OPTION,
JOptionPane.INFORMATION_MESSAGE);
} catch (Exception e) {
e.printStackTrace();
}
} else {
text1.setText("");
text2.setText("");
text3.setText("");
JOptionPane.showConfirmDialog(null, "帐号已存在,请新建一个!",
"Info", JOptionPane.CLOSED_OPTION,
JOptionPane.INFORMATION_MESSAGE);
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
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("Register 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()) {
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 + "'");
JOptionPane.showConfirmDialog(null, "注册成功!", "Info",
JOptionPane.CLOSED_OPTION,
JOptionPane.INFORMATION_MESSAGE);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -