作业 GUI 化的简单签到程序

将命令行程序GUI化还是挺蛋疼的          

但是一下午出来还是弄出了这个东西

虽然    感觉做得有些难看   

但是   勉强说得过去吧

话不多说   

没看过的请参考 http://blog.csdn.net/cp_wl/article/details/20570369

另外    没有封装成jar包    还需要一定的命令行支持

学生名单下载:http://pan.baidu.com/s/1sjCpxMX 
“简单签到程序”网页:http://blog.csdn.net/dyz1982/article/details/20311823  
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

import javax.swing.*;

public class grah extends JFrame implements ActionListener {
	static int count2 = 0;//读取到的行数
	static JButton but1 = new JButton("到");//两个按钮
	static JButton but2 = new JButton("缺席");
	static JLabel textfield = new JLabel("嗯哼", JLabel.CENTER);//标签   用于显示名字和号数。
	static JTextArea textarea = new JTextArea();//文本域,用于最后的输入
	static String namel[][];//字符组    将花名册读入数组
	static int count = 0;//人数
	static int nAbsent=0;//缺席人数
	static String strAbsent;//缺席人名
	static String inname,outname;


	public static void main(String[] args) throws FileNotFoundException {
		
		if (args.length != 2) {
			System.out.println("参数输入不对");
			System.out.println("使用方法(示例):java RegisterApp 名单文件名称  班级名称");
			System.exit(0);
		}

		inname=args[0];
		outname=args[1];
		File filein = new File(inname);

		Scanner fin = new Scanner(filein);
		Scanner fin1 = new Scanner(filein);

		while (fin.hasNext()) {//确定人数
			count++;
			fin.nextLine();
		}
		//System.out.println(count);
		fin.close();
		namel = new String[count][2];
		for (int a = 0; a < count; a++) {//读入数组
			namel[a][0] = fin1.nextLine();
			//System.out.println(namel[a][0]);
		}
		fin1.close();
		/************************************图型部分*********************************************/
		textfield.setText(namel[count2][0]);
		grah g = new grah();
		g.setLayout(new BorderLayout());

		g.add("North", textfield);
		g.add("East", but1);
		g.add("West", but2);
		g.add("Center",textarea);
		g.setSize(300, 100);
		g.setVisible(true);
		textarea.setEditable(false);
		// TODO Auto-generated method stub

		but1.addActionListener(g);

		but2.addActionListener(g);

		g.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		/**************************************************************************************/

	}

	public void actionPerformed(ActionEvent e) {

		if (e.getActionCommand().equals("到") && count2 < count) {
			
			//到时
			
			textfield.setText(namel[count2][0]);
			namel[count2][1] = "1";
			count2++;

			
		} else if (e.getActionCommand().equals("缺席") && count2 < count) {
			
			//缺席时
			
			textfield.setText(namel[count2][0]);
			namel[count2][1] = "0";
			strAbsent=strAbsent+namel[count2][0]+"    "+"\r\n";
			count2++;
			nAbsent++;
			
			
		} else if (count2 == count) {
			
			//点完时
			
			File fileout = new File(outname+ redate() + ".txt");
			try {
				@SuppressWarnings("resource")
				PrintWriter fout = new PrintWriter(fileout);

				for (int a = 0; a < count; a++) {
					String s = namel[a][0] + "    " + namel[a][1];
					fout.println(s);
				}
				fout.close();
				textarea.setText("考勤结束."+"\r\n"+"一共有"+nAbsent+"个同学缺课"+"\r\n"+"分别是"+strAbsent+"\r\n"+"点击右上角关闭");
			}
			catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			
			
		}

	}

	public static String redate() {//返回日期
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHMM");// 可以方便地修改日期格式
		String strDate = dateFormat.format(now);
		// System.out.println("当前时间:"+strDate);
		return strDate;

	}

}
运行中:


运行完成



谢谢收看

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值