您的位置:首页 > 产品设计 > UI/UE

作业 GUI 化的简单签到程序

2014-03-12 21:21 531 查看
将命令行程序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;

}

}
运行中:



运行完成



谢谢收看
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java 源代码 gui