📄 增加用户.java~1~
字号:
package 学生信息管理系统;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.sql.*;
import com.borland.dbswing.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2001</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class 增加用户 extends JDialog {
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextField jTextField1 = new JTextField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
Connection connection = null;
Statement statement = null;
JTextField jTextField4 = new JTextField();
JPasswordField jPasswordField1 = new JPasswordField();
JdbComboBox jdbComboBox1 = new JdbComboBox();
public 增加用户(Frame frame, String title, boolean modal) {
super(frame, title, modal);
try {
jbInit();
pack();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
public 增加用户() {
this(null, "", false);
}
private void jbInit() throws Exception {
jLabel1.setFont(new java.awt.Font("Dialog", 0, 15));
jLabel1.setToolTipText("");
jLabel1.setText("用户:");
jLabel1.setBounds(new Rectangle(15, 14, 87, 29));
this.getContentPane().setLayout(null);
jLabel2.setFont(new java.awt.Font("Dialog", 0, 15));
jLabel2.setText("密码:");
jLabel2.setBounds(new Rectangle(15, 56, 89, 40));
jLabel3.setFont(new java.awt.Font("Dialog", 0, 15));
jLabel3.setText("权限:");
jLabel3.setBounds(new Rectangle(13, 106, 57, 33));
jTextField1.setFont(new java.awt.Font("Dialog", 0, 15));
jTextField1.setText("");
jTextField1.setBounds(new Rectangle(79, 21, 98, 24));
jButton1.setBounds(new Rectangle(233, 23, 93, 31));
jButton1.setFont(new java.awt.Font("Dialog", 0, 15));
jButton1.setText("增加");
jButton1.addActionListener(new 增加用户_jButton1_actionAdapter(this));
jButton2.setBounds(new Rectangle(233, 70, 91, 29));
jButton2.setFont(new java.awt.Font("Dialog", 0, 15));
jButton2.setText("返回");
jButton2.addActionListener(new 增加用户_jButton2_actionAdapter(this));
jTextField4.setFont(new java.awt.Font("Dialog", 0, 15));
jTextField4.setBorder(BorderFactory.createLoweredBevelBorder());
jTextField4.setText("");
jTextField4.setBounds(new Rectangle(16, 163, 162, 39));
jPasswordField1.setFont(new java.awt.Font("Dialog", 0, 15));
jPasswordField1.setText("");
jPasswordField1.setBounds(new Rectangle(79, 64, 98, 25));
jdbComboBox1.setFont(new java.awt.Font("Dialog", 0, 15));
jdbComboBox1.setItems(new String[] {"学生", "老师"});
jdbComboBox1.setSelectedIndex(-1);
jdbComboBox1.setBounds(new Rectangle(78, 112, 99, 26));
this.getContentPane().add(jLabel1, null);
this.getContentPane().add(jLabel2, null);
this.getContentPane().add(jTextField1, null);
this.getContentPane().add(jButton1, null);
this.getContentPane().add(jButton2, null);
this.getContentPane().add(jLabel3, null);
this.getContentPane().add(jTextField4, null);
this.getContentPane().add(jPasswordField1, null);
this.getContentPane().add(jdbComboBox1, null);
}
void cancel() {
dispose();
}
void jButton2_actionPerformed(ActionEvent e) {
if (e.getSource() == jButton2) {
cancel();
}
}
void jButton1_actionPerformed(ActionEvent e) {
//增加确定
try {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // 实例化JDBC-ODBC桥的驱动
}
catch (ClassNotFoundException ex) {
}
connection = DriverManager.getConnection("jdbc:odbc:学生信息管理", "sample",
""); // 连接数据库
// 创建Statement接口对象
statement = connection.createStatement();
String 用户_用户=jTextField1.getText();
String 用户_密码=jPasswordField1.getText();
String 用户_权限="";
if(String.valueOf(jdbComboBox1.getSelectedItem())=="老师"){用户_权限+="1"; }
else {用户_权限+="0";}
if(用户_用户.length()>0){
String str1="INSERT INTO 用户(用户,密码,权限)";
str1+="VALUES ('"+用户_用户+"',";
str1+="'"+用户_密码+"'"+",";
str1+=用户_权限+")";
statement.executeUpdate(str1);
jTextField4.setText("成功增加");}//if
else jTextField4.setText("增加失败");
}catch(SQLException e2){jTextField4.setText("增加失败");}
}//jubutton1
}
class 增加用户_jButton2_actionAdapter implements java.awt.event.ActionListener {
增加用户 adaptee;
增加用户_jButton2_actionAdapter(增加用户 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class 增加用户_jButton1_actionAdapter implements java.awt.event.ActionListener {
增加用户 adaptee;
增加用户_jButton1_actionAdapter(增加用户 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -