⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 studentsadd.java~9~

📁 学生信息管理系统,包括成绩查询,成绩排序,用ACCESS做数据库连接
💻 JAVA~9~
字号:
package Chapter1;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.awt.Rectangle;
import java.awt.Font;

public class StudentsAdd extends JFrame implements ActionListener
{
   public static final int WIDTH=400;
   public static final int HEIGHT=400;
  JLabel jLabel1 = new JLabel();
  JTextField jTextField1 = new JTextField();
  JLabel jLabel2 = new JLabel();
  JTextField jTextField2 = new JTextField();
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  JButton jButton3 = new JButton();
   public StudentsAdd()
   {
     setSize(WIDTH,HEIGHT);
     setTitle("添加学生");
     Container contentPane=getContentPane();
     contentPane.setBackground(Color.green);
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
   }
   public void actionPerformed(ActionEvent e)
   {
     if(e.getActionCommand().equals("添加"))
        { //用于获取用户输入的信息

           try
           {
             String url="jdbc:odbc:MySecondAccess";
             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
             Connection con=DriverManager.getConnection(url,"","");
             Statement stmt=con.createStatement();

             String  SQLOrder="INSERT INTO StudentsInformation VALUES('"+jTextField1.getText()+"','Bob','"+jTextField2.getText()+"')";
             stmt.executeUpdate(SQLOrder);
             stmt.close();
             con.close();
             JOptionPane.showMessageDialog(null,"添加成功!","提示信息",JOptionPane.INFORMATION_MESSAGE);
           }
           catch(Exception ex)
           {
             System.out.println(ex.getStackTrace());
             System.out.println(ex.getMessage());
           }
        }
      else if (e.getActionCommand().equals("重置"))
      {
        jTextField1.setText("");
        jTextField2.setText("");
      }
      else if  (e.getActionCommand().equals("返回"))
      { this.setVisible(false);
        ManagerInterface n=new ManagerInterface();
        n.setVisible(true);
      }
   }
   public static void main(String[] args)
   {
       StudentsAdd n=new StudentsAdd();
       n.setVisible(true);
   }
  private void jbInit() throws Exception {
    jLabel1.setFont(new java.awt.Font("Dialog", 1, 13));
    jLabel1.setText("请输入您要添加的学生的学号:");
    jLabel1.setBounds(new Rectangle(13, 54, 191, 27));
    this.getContentPane().setLayout(null);
    jTextField1.setText("");
    jTextField1.setBounds(new Rectangle(202, 57, 95, 21));
    jLabel2.setFont(new java.awt.Font("Dialog", 1, 13));
    jLabel2.setText("请输入他的密码: ");
    jLabel2.setBounds(new Rectangle(95, 111, 140, 20));
    jTextField2.setText("");
    jTextField2.setBounds(new Rectangle(203, 108, 94, 21));
    jButton1.setBounds(new Rectangle(72, 195, 66, 30));
    jButton1.setFont(new java.awt.Font("Dialog", 1, 13));
    jButton1.setText("添加");
    jButton2.setBounds(new Rectangle(173, 194, 66, 31));
    jButton2.setFont(new java.awt.Font("Dialog", 1, 13));
    jButton2.setText("重置");
    jButton3.setBounds(new Rectangle(275, 194, 67, 31));
    jButton3.setFont(new java.awt.Font("Dialog", 1, 13));
    jButton3.setText("返回");
    this.getContentPane().add(jLabel1, null);
    this.getContentPane().add(jTextField1, null);
    this.getContentPane().add(jLabel2, null);
    this.getContentPane().add(jTextField2, null);
    this.getContentPane().add(jButton1, null);
    this.getContentPane().add(jButton3, null);
    this.getContentPane().add(jButton2, null);
    jButton1.addActionListener(this);
    jButton2.addActionListener(this);
    jButton3.addActionListener(this);
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -