代码有点坑!!!
实现功能不多!!!
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Tu extends Frame implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* @param args
* @throws FileNotFoundException
*/
static String[][] stringArray ;
static Frame f = new Frame("图形界面签到程序");
static Label lb = new Label("学生姓名");
static TextField tf = new TextField(10);
static Button b1 = new Button("到");
static Button b2 = new Button("缺德");
static Label b = new Label("考勤结果");
static TextArea ta = new TextArea(15,30);
static String t = "缺席名单:";
static int count2 = 0;
static int count = 0;
// TODO Auto-generated method stub
@SuppressWarnings("resource")
public static void main(String[] args) throws FileNotFoundException {
File fr=new File("d:\\users","wl121.txt");
Scanner sc = new Scanner(fr);
Scanner st = new Scanner(fr);
while (sc.hasNext()) {//确定人数
count++;
sc.nextLine();
}
stringArray = new String[count][2];
for (int a = 0; a < count ; a++) {//读入数组
stringArray[a][0] = st .nextLine();
}
sc.close();
st.close();
//tf.setText(strName);
tf.setText(stringArray[count2][0]);//
Tu tu = new Tu();
tu.setLayout(new FlowLayout(FlowLayout.LEFT,20,40));
tu.add(lb);
tu.add(tf);
tu.add(b1);
tu.add(b2);
tu.add(b);
tu.add(ta);
tu.setVisible(true);
tu.setSize(350,300);
b1.addActionListener(tu);
b2.addActionListener(tu);
ta.setEditable(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==b1 ){
tf.setText(stringArray[count2][0]);//
count2++;//
}
else if(e.getSource()==b2 ){
String strAbsent =stringArray[count2][0];//
ta.setText(t+strAbsent+" "+"\r\n");
}
}
}