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

📄 delete_student_inf.java

📁 用来管理在校学生的出勤.作息等的管理系统
💻 JAVA
字号:
package stu.view;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

public class delete_student_inf extends JFrame {

	private static final long serialVersionUID = -5689591713513219602L;


	public delete_student_inf() {
		super();
		getContentPane().setLayout(null);
		setBounds(100, 100, 460, 288);
		setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		setResizable(false);
		
		final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		final Dimension my = this.getSize();
		setLocationByPlatform(true);
		setLocation((screen.width - my.width) / 2,
				(screen.height - my.height) / 2);
		setVisible(true);

		final JLabel label = new JLabel();
		label.setFont(new Font("宋体", Font.PLAIN, 16));
		label.setText("请输入要删除的学生");
		label.setBounds(165, 38, 157, 22);
		getContentPane().add(label);

		final JTextField textField = new JTextField();
		textField.setBounds(212, 93, 136, 22);
		getContentPane().add(textField);

		final JButton button = new JButton();
		button.setFont(new Font("宋体", Font.PLAIN, 14));
		button.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				String url = "jdbc:odbc:DB_Student";
				Connection con1;
				
				int result = JOptionPane.showOptionDialog(null, "是否删除该学生信息?",
						"系统提示", JOptionPane.YES_NO_OPTION,
						JOptionPane.QUESTION_MESSAGE, null, new String[] { "是",
								"否" }, "否");
				if(result==JOptionPane.OK_OPTION){
				try {
					con1 = DriverManager.getConnection(url);
					String str = "delete from 学生表 where 学号='"
							+ textField.getText() + "'";
					String str1="delete from 考勤表 where 学号='"
							+ textField.getText() + "'";
					String str2="delete from 成绩表 where 学号='"
						+ textField.getText() + "'";
					
					Statement pst1 = con1.createStatement();
					if (pst1.executeUpdate(str) != 0){
						pst1.executeUpdate(str1);
						pst1.executeUpdate(str2); 
						JOptionPane.showMessageDialog(null, "学生信息删除成功!",
								"系统提示!", JOptionPane.INFORMATION_MESSAGE);
					}
					else
						JOptionPane.showMessageDialog(null, "可能没这个学生!",
								"系统提示!", JOptionPane.ERROR_MESSAGE);

					pst1.close();
					con1.close();
					textField.setText("");
				} catch (Exception e1) {

					//e1.printStackTrace();
					JOptionPane.showMessageDialog(null, "学生信息删除失败!", "系统提示!",
							JOptionPane.ERROR_MESSAGE);
				}
				}
				else{}
			}
		});
		button.setText("确定");
		button.setBounds(144, 150, 62, 28);
		getContentPane().add(button);
		setTitle("删除学生信息");
		setVisible(true);

		final JLabel label_1 = new JLabel();
		label_1.setFont(new Font("宋体", Font.PLAIN, 16));
		label_1.setText("学    号:");
		label_1.setBounds(123, 91, 83, 22);
		getContentPane().add(label_1);

		final JButton button_1 = new JButton();
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				
				dispose();
			}
		});
		button_1.setFont(new Font("宋体", Font.PLAIN, 14));
		button_1.setText("退出");
		button_1.setBounds(264, 150, 62, 28);
		getContentPane().add(button_1);
	}

}

⌨️ 快捷键说明

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