import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import javax.swing.*;
public class randomShow extends JFrame{
JLabel jl,jl1;
JButton jbt;
Random rd;
	public static void main(String[] args) throws Exception{
		randomShow rn=new randomShow();
		rn.init();
}
	public void init() {
	jl= new JLabel("今天你很幸运:");//提示标签页面
	jl.setHorizontalAlignment(SwingConstants.CENTER);//设置标签居中
	jl.setFont(new java.awt.Font("随机点名",1,35));//设置字体大小
	jl1=new JLabel();
	jl1.setHorizontalAlignment(SwingConstants.CENTER);//设置名字显示的标签居中
	jbt=new JButton("开始点名");
	jbt.addActionListener(new ActionListener() {
			
		@Override
		public void actionPerformed(ActionEvent argo) {
			String n=null;
			try {
				n= getRandomName();
			}catch (NumberFormatException e) {
				e.printStackTrace();
			}catch (Exception e) {
				e.printStackTrace();
			}
			jl1.setText(n);//设置jl1标签文字
			jl1.setFont(new Font(n,1,35));//设置字体
			jl1.setForeground(Color.red);
		}
	});
	Container p=this.getContentPane();
	p.setLayout(new BorderLayout(3,1));
	p.add(jl,BorderLayout.NORTH);
	p.add(jl1,BorderLayout.CENTER);
	p.add(jbt,BorderLayout.SOUTH);
	this.pack();
	this.setSize(300,300);
	this.setVisible(true);
	this.setTitle("简易点名器");
	this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	this.setLocation(300, 300);
	}
public String getRandomName() throws IOException{
	String filePath="file\\randow.txt";
	BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(filePath),"GBK"));
	ArrayList<String>list = new ArrayList<String>();
	String line = null;
	while((line=br.readLine())!=null) {
		list.add(line);
	}
	br.close();
	String[] mingdan=(String[])list.toArray(new String[0]);
	int R = (int)(Math.random()*mingdan.length);
	return mingdan[R];
}

}