作业 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
运行完成
谢谢收看
但是一下午出来还是弄出了这个东西
虽然 感觉做得有些难看
但是 勉强说得过去吧
话不多说
没看过的请参考 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; } }运行中:
运行完成
谢谢收看
相关文章推荐
- 第三周作业(GUI简单签到程序和判断是否闰年)
- 第三周作业-实现随机点名的签到程序和计算闰年的简单程序
- 丁老师的作业_修改并运行“简单签到程序”
- 第三周作业 gui图形界面化签到程序改版
- 第二周作业:老师的签到程序GUI
- 一个简单的matlab图形界面程序GUI
- 简单的签到程序
- 对matlab GUI程序简单加密
- python GUI编程——wxpython编写简单记事本程序
- 第三周作业-实现随机点名的签到程序
- (转)深入浅出WPF(2)——解剖最简单的GUI程序
- 编程作业 简单的学生信息处理程序实现[北京大学C++课程]
- 5月份为应付老师的作业写的简单的图片识别的程序
- 非GUI-Qt程序运行后显示Console(简单好用)
- 斯坦福作业2:简单Java程序 控制台作业合集
- 一个简单的 Qt GUI 程序
- 【作业】简单分形树绘制程序
- 斯坦福作业2:简单Java程序 图形作业合集
- 作业一:创建个人技术博客、自我介绍、简单的C程序
- Java图形用户界面(GUI)工具包swing来写一个简单的留言板程序(不带数据库)