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

📄 test_work.java

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

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;

public class test_work extends JFrame implements ActionListener {

	private static final long serialVersionUID = -849279248753966462L;

	private ButtonGroup buttonGroup = new ButtonGroup();

	static JTextField number = new JTextField();

	static JTextField name = new JTextField();

	static JRadioButton is_come = new JRadioButton();

	static JRadioButton is_nocome = new JRadioButton();

	static JLabel show_photo = new JLabel();

	work run = new work();

	public test_work() {
		super();
		getContentPane().setLayout(null);
		setBounds(100, 100, 482, 375);
		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, 15));
		label.setText("学号:");
		label.setBounds(33, 41, 80, 26);
		getContentPane().add(label);

		final JLabel label_1 = new JLabel();
		label_1.setFont(new Font("宋体", Font.PLAIN, 15));
		label_1.setText("姓名:");
		label_1.setBounds(33, 105, 80, 26);
		getContentPane().add(label_1);

		final JLabel label_2 = new JLabel();
		label_2.setFont(new Font("宋体", Font.PLAIN, 15));
		label_2.setText("签到情况:");
		label_2.setBounds(33, 171, 80, 26);
		getContentPane().add(label_2);

		number.setEditable(false);
		number.setBounds(33, 73, 171, 26);
		getContentPane().add(number);

		name.setEditable(false);
		name.setBounds(33, 137, 171, 26);
		getContentPane().add(name);

		buttonGroup.add(is_come);
		is_come.setFont(new Font("宋体", Font.PLAIN, 15));
		is_come.setText("到");
		is_come.setSelected(true);
		is_come.setBounds(33, 203, 107, 26);
		getContentPane().add(is_come);

		buttonGroup.add(is_nocome);
		is_nocome.setFont(new Font("宋体", Font.PLAIN, 15));
		is_nocome.setText("缺到");
		is_nocome.setBounds(33, 235, 107, 26);
		getContentPane().add(is_nocome);

		final JLabel label_3 = new JLabel();
		label_3.setFont(new Font("宋体", Font.PLAIN, 14));
		final TitledBorder titledBorder = new TitledBorder(new TitledBorder(
				null, "", TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, null, null), "照片",
				TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, null, null);
		titledBorder.setTitleFont(new Font("宋体", Font.PLAIN, 14));
		final TitledBorder titledBorder_1 = new TitledBorder(null, "照片",
				TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, null, null);
		titledBorder_1.setTitleFont(new Font("宋体", Font.PLAIN, 15));
		label_3.setBorder(titledBorder_1);
		label_3.setBounds(238, 41, 208, 273);
		getContentPane().add(label_3);

		show_photo.setBounds(250, 60, 185, 243);
		getContentPane().add(show_photo);
		//
		setTitle("正在点名...");
		setVisible(true);

		final JButton button = new JButton();
		button.setFont(new Font("", Font.PLAIN, 14));
		button.addActionListener(this);
		button.setText("暂停");
		button.setBounds(33, 286, 79, 28);
		getContentPane().add(button);

		final JButton button_1 = new JButton();
		button_1.setFont(new Font("", Font.PLAIN, 14));
		button_1.addActionListener(this);
		button_1.setText("继续");
		button_1.setBounds(125, 286, 79, 28);
		getContentPane().add(button_1);
		run.start();

	}

	public void actionPerformed(final ActionEvent e) {
		if (((String) e.getActionCommand()).equals("暂停"))
			run.is_run = false;

		else
			run.is_run = true;

	}

}

class work extends Thread {

	String num = "";

	String name = "";

	String classname = "";

	String coursename = "";

	InputStream is = null;

	SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");

	String date = sdf.format(new Date());

	boolean is_run = true;

	String str = "select 学号,姓名,照片 from 学生表 where 班级名 = '" + classname + "'";

	String str1 = "select DISTINCT 班级名 from 授课关系表";

	String str2;

	String url = "jdbc:odbc:DB_Student";

	Connection con1;

	public void run() {
		try {
			con1 = DriverManager.getConnection(url);
		} catch (SQLException e2) {
			//e2.printStackTrace();
		}
		Statement st;
		ResultSet rs;
		try {
			st = con1.createStatement();
			rs = st.executeQuery(str1);
			Object[] classValues = new Object[1000];
			int len = 0;
			while (rs.next()) {
				classValues[len++] = rs.getString(1);
			}
			classname = (String) JOptionPane.showInputDialog(null, "请选择班级:",
					"Input", JOptionPane.INFORMATION_MESSAGE, null,
					classValues, classValues[0]);
			rs.close();
			st.close();

		} catch (SQLException e) {
			//e.printStackTrace();
		}

		try {
			str2 = "select 课程名 from 授课关系表 where 班级名='"+ classname +"'";
			st = con1.createStatement();
			rs = st.executeQuery(str2);
			Object[] courseValues = new Object[1000];
			int len = 0;
			while (rs.next()) {
				courseValues[len++] = rs.getString(1);
			}
			coursename = (String) JOptionPane.showInputDialog(null, "请输入课程:",
					"Input", JOptionPane.INFORMATION_MESSAGE, null,
					courseValues, courseValues[0]);
			rs.close();
			st.close();

		} catch (SQLException e) {
			//e.printStackTrace();
		}
		//System.out.println(classname);
		//System.out.println(coursename);
		try {
			str = "select 学号,姓名,照片 from 学生表 where 班级名 = '" + classname + "'";
			st = con1.createStatement();
			rs = st.executeQuery(str);
			while (rs.next()) {
				while (true) {
					if (is_run == true) {
						//System.out.println(is_run);
						break;
					}

				}
				InputStream is = rs.getBinaryStream(3);
				FileOutputStream out = new FileOutputStream("copycopy.gif");
				File file = new File("copycopy.gif");
				int data;
				while ((data = is.read()) != -1)
					out.write(data);
				is.close();
				Image image = Toolkit.getDefaultToolkit().getImage(
						"copycopy.gif");
				image = image.getScaledInstance(
						test_work.show_photo.getWidth(), test_work.show_photo
								.getHeight(), Image.SCALE_DEFAULT);
				ImageIcon img = new ImageIcon(image);
				img.setImage(image);
				test_work.show_photo.setIcon(img);
				file.delete();
				test_work.number.setText(rs.getString(1));
				test_work.name.setText(rs.getString(2));

				test_work.is_come.setSelected(true);

				try {
					Thread.sleep(5000);
					Statement st1 = con1.createStatement();
					String is_come = "";
					if (test_work.is_come.isSelected() == true)
						is_come = "到";
					if (test_work.is_nocome.isSelected() == true)
						is_come = "未到";

					String str = "insert into 考勤表 values('"
							+ test_work.number.getText() + "','" + coursename
							+ "','" + classname + "','" + is_come + "','"
							+ date + "')";
					//System.out.println(str);
					st1.execute(str);
					//st.close();
				} catch (Exception e1) {

				}

			}
			JOptionPane.showMessageDialog(null, "点名完毕!", "系统提示!",
					JOptionPane.INFORMATION_MESSAGE);

			con1.close();
		} catch (Exception e1) {
		}

	}
}

⌨️ 快捷键说明

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