📄 fpanel19.java
字号:
package src1;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import javax.swing.*;
import java.awt.*;
public class FPanel19 extends FunctionPanel implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
//private JLabel label = new JLabel(" FPanel 17 ");
private Connection connect=null;
private Statement st=null;
// private ResultSet rset=null;
private JLabel label1,label2,label3;
private JTextField tf1;
JPasswordField pw2,pw3;
private JButton bt1,bt2;
private JPanel panel1,panel2;
private String sql=null;
public FPanel19() {
// TODO 自动生成构造函数存根
operationLabel.setText("操作:新增用户");
this.setLayout(null);
label1 = new JLabel(" 用 户名");
label2 = new JLabel(" 密 码");
label3 = new JLabel(" 确认密码");
label1.setIcon(new ImageIcon("./src/icons/25.gif"));
label2.setIcon(new ImageIcon("./src/icons/25.gif"));
label3.setIcon(new ImageIcon("./src/icons/25.gif"));
tf1 = new JTextField(12);
pw2 = new JPasswordField(6);
pw3 = new JPasswordField(6);
bt1 = new JButton("提交");
bt2 = new JButton("重填");
bt1.setIcon(new ImageIcon("./src/icons/27.gif"));
bt2.setIcon(new ImageIcon("./src/icons/27.gif"));
panel1 =new JPanel();
panel2=new JPanel();
panel1.setBounds(150,150,260,140);
panel2.setBounds(150,300,260,40);
panel1.setLayout(null);
label1.setBounds(20, 20, 100, 25);
tf1.setBounds(130,20,100,25);
label2.setBounds(20, 50, 100, 25);
pw2.setBounds(130,50,100,25);
label3.setBounds(20, 80, 100, 25);
pw3.setBounds(130,80,100,25);
panel1.add(label1);panel1.add(tf1);
panel1.add(label2);panel1.add(pw2);
panel1.add(label3);panel1.add(pw3);
panel2.add(bt1);panel2.add(bt2);
panel1.setBackground(new Color(240,255,255));
panel2.setBackground(new Color(240,255,255));
this.add(panel1);
this.add(panel2);
//panel1.setBorder(new OwnBorder(2,Color.green));
//panel3.setBorder(new OwnBorder(2,Color.LIGHT_GRAY));
bt1.addActionListener(this);
bt2.addActionListener(this);
this.setVisible(false);
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()== bt1)
{
if(tf1.getText().trim().equals("")){
JOptionPane.showMessageDialog(null,"用户名不许为空!");
return;
}
if(String.copyValueOf(pw2.getPassword()).trim().equals("")){
JOptionPane.showMessageDialog(null,"密码不许为空!");
return;
}
if(!String.copyValueOf(pw2.getPassword()).trim().equals(String.copyValueOf(pw3.getPassword()).trim())){
JOptionPane.showMessageDialog(null,"两次输入的新密码不一样!");
return;
}
sql="Insert into UInf values( '"+
tf1.getText().trim()+"','"+
String.copyValueOf(pw2.getPassword()).trim()+"');";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
try{
connect=DriverManager.getConnection("jdbc:odbc:MSSQL");
st=connect.createStatement();
//rset=st.executeQuery(sql);
//connect.close();
}catch (SQLException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
System.out.print(e3);
}
try {
st.executeUpdate(sql);
connect.commit();
JOptionPane.showMessageDialog(null, "用户注册成功!");
} catch (SQLException e4) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(null, "用户注册失败!");
e4.printStackTrace();
}
}
if(e.getSource()== bt2){
tf1.setText("");
pw2.setText("");
pw3.setText("");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -