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

📄 kechengbiao.java

📁 用来管理在校学生的出勤.作息等的管理系统
💻 JAVA
字号:
/*
 * @author 黎龙飞 , 创建日期 2008-5-20
 *
 * Blog : http://lilongfei1030.blog.163.com
 */
package stu.view;

import java.awt.Color;
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.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.TitledBorder;
import javax.swing.table.TableModel;

import stu.util.ConnectDatabase;
import stu.util.getResults;

public class KeChengBiao extends JFrame {

	private JTable table;

	private JComboBox comboBox_1;

	private JComboBox comboBox;

	JScrollPane scrollPane;
	
	TableModel tableModel;

	private static final long serialVersionUID = -1027067170164157471L;

	public KeChengBiao() {
		super();
		getContentPane().setLayout(null);
		setBounds(100, 100, 375, 340);
		setDefaultCloseOperation(JFrame.DISPOSE_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 String sql = "select * from 班级表";
		String[] columnName = null;
		Connection con = new ConnectDatabase().getResultString();
		try {
			Statement stm = con.createStatement();
			ResultSet rs = stm.executeQuery(sql);
			int j = 0;
			while (rs.next())
				j++;
			columnName = new String[j];
			int k = 0;
			rs = stm.executeQuery(sql);
			while (rs.next()) {
				columnName[k++] = (String) rs.getObject(2);
			}
			/*for (int i = 0; i < k; i++)
				System.out.println(columnName[i] + " ");*/
		} catch (SQLException e1) {
			//e1.printStackTrace();
		}

		comboBox = new JComboBox(columnName);
		comboBox.setFont(new Font("", Font.PLAIN, 14));
		comboBox.setBounds(57, 214, 112, 27);
		getContentPane().add(comboBox);

		String sql1 = "select * from 课程表";
		String[] columnName1 = null;
		Connection con1 = new ConnectDatabase().getResultString();
		try {
			Statement stm = con1.createStatement();
			ResultSet rs1 = stm.executeQuery(sql1);

			int j = 0;
			while (rs1.next())
				j++;
			columnName1 = new String[j];
			int k = 0;
			rs1 = stm.executeQuery(sql1);
			while (rs1.next()) {
				columnName1[k++] = (String) rs1.getObject(2);
			}
			/*for (int i = 0; i < k; i++)
				System.out.println(columnName1[i] + " ");
*/
		} catch (SQLException e1) {
			e1.printStackTrace();
		}

		comboBox_1 = new JComboBox(columnName1);
		comboBox_1.setFont(new Font("", Font.PLAIN, 14));
		comboBox_1.setBounds(227, 214, 112, 27);
		getContentPane().add(comboBox_1);

		final JLabel label = new JLabel();
		label.setFont(new Font("", Font.PLAIN, 15));
		label.setText("班级:");
		label.setBounds(22, 218, 35, 18);
		getContentPane().add(label);

		final JLabel label_1 = new JLabel();
		label_1.setFont(new Font("", Font.PLAIN, 15));
		label_1.setText("课程:");
		label_1.setBounds(192, 218, 35, 18);
		getContentPane().add(label_1);

		scrollPane = new JScrollPane();
		final TitledBorder titledBorder = new TitledBorder(null, "班级课程表",
				TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, null, null);
		titledBorder.setTitleFont(new Font("宋体", Font.PLAIN, 15));
		scrollPane.setBorder(titledBorder);
		scrollPane.setBounds(22, 10, 317, 186);
		getContentPane().add(scrollPane);

		flash();

		final JButton button = new JButton();
		button.setFont(new Font("", Font.PLAIN, 14));
		button.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {

				//System.out.println(comboBox.getSelectedItem());
				String sql = "insert  into 授课关系表 values('"
						+ comboBox.getSelectedItem() + "','"
						+ comboBox_1.getSelectedItem() + "')";
				Connection con = new ConnectDatabase().getResultString();
				try {
					Statement stm = con.createStatement();
					stm.executeUpdate(sql);
					JOptionPane.showMessageDialog(null, "添加成功!", "系统提示",
							JOptionPane.INFORMATION_MESSAGE);
					flash();
				} catch (Exception e3) {
					// e3.printStackTrace();
					JOptionPane.showMessageDialog(null, "数据已经存在!", "系统提示",
							JOptionPane.ERROR_MESSAGE);
				}
			}
		});
		button.setText("添加");
		button.setBounds(103, 264, 66, 28);
		getContentPane().add(button);

		final JButton button_1 = new JButton();
		button_1.setFont(new Font("", Font.PLAIN, 14));
		button_1.addActionListener(new ActionListener() {

			public void actionPerformed(final ActionEvent e) {
				int currow = table.getSelectedRow();

				try {

					String sql2 = "delete from 授课关系表  where  班级名='"
							+ (String) table.getValueAt(currow, 0)
							+ "'and 课程名='"
							+ (String) table.getValueAt(currow, 1) + "'";
					
					String sql3="delete from 考勤表 where  班级名='"
							+ (String) table.getValueAt(currow, 0)
							+ "'and 课程名='"
							+ (String) table.getValueAt(currow, 1) + "'";
					
					String sql4="delete from 成绩表 where  课程名='"
						+ (String) table.getValueAt(currow, 1) + "'and 成绩表.学号 in(select 成绩表.学号 from 学生表,成绩表 where 学生表.学号=成绩表.学号 and 班级名='"
						+ (String) table.getValueAt(currow, 0)
						+ "')";
					
					int result = JOptionPane.showOptionDialog(null,
							"是否删除该课程信息?", "系统提示", JOptionPane.YES_NO_OPTION,
							JOptionPane.QUESTION_MESSAGE, null, new String[] {
									"是", "否" }, "否");
					if (result == JOptionPane.OK_OPTION) {
						try {
							//new getResults().Results(sql2);
							Connection con = new ConnectDatabase().getResultString();
							Statement stm = con.createStatement();
							stm.executeUpdate(sql2);
							stm.executeUpdate(sql3);
							stm.executeUpdate(sql4);
							
							JOptionPane.showMessageDialog(null, "课程信息删除成功","系统提示",JOptionPane.INFORMATION_MESSAGE);
							flash();
						
						} catch (Exception e1) {
							e1.printStackTrace();
						}
					} else {

					}
				} catch (Exception e1) {
					JOptionPane.showMessageDialog(null, "请选择要删除的信息!", "系统提示",
							JOptionPane.WARNING_MESSAGE);
				}
			}

		});

		button_1.setText("删除");
		button_1.setBounds(193, 264, 66, 28);
		getContentPane().add(button_1);

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

		final JButton button_3 = new JButton();
		button_3.setFont(new Font("", Font.PLAIN, 14));
		button_3.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				flash();
			}
		});
		button_3.setText("刷新");
		button_3.setBounds(22, 264, 66, 28);
		getContentPane().add(button_3);
		//
	}

	public void flash() {

		TableModel tableModel;
		String str = "select * from 授课关系表";
		try {
			tableModel = new getResults().Results(str);
			table = new JTable(tableModel);
			scrollPane.setViewportView(table);
			table.setSelectionForeground(Color.RED);
			//System.out.println("表中共有: " + table.getRowCount() + "条记录.");

		} catch (Exception e3) {
			//e3.printStackTrace();
		}
	}
}

⌨️ 快捷键说明

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