package Dianm;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.Color;
import java.awt.Font;
import javax.swing.SwingConstants;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;

public class Dianming extends JFrame {
private JPanel contentPane;
private static JTextField textField;
private JLabel label;
private ArrayList<String> names = new ArrayList<String>();
private String File = "a.txt";//设置地址,必须为txt文本

private File f;
private JButton btnNewButton;
private FileReader fr;
private BufferedReader br;
private String strName;

/**
* Launch the application.
*/
public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Dianming frame = new Dianming();
frame.setTitle("点名软件");
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});

}

/**
* Create the frame.
*/
public Dianming() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 427, 328);
contentPane = new JPanel();
contentPane.setBackground(new Color(160, 82, 45));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

btnNewButton = new JButton("\u5F00\u59CB");
btnNewButton.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
write();
textField.setText(strName);
/*Text te=new Text();
te.start();*/
}
});
btnNewButton.setForeground(Color.RED);
btnNewButton.setFont(new Font("微软雅黑", Font.BOLD, 24));
btnNewButton.setBackground(new Color(173, 255, 47));
btnNewButton.setBounds(142, 188, 113, 52);
contentPane.add(btnNewButton);

textField = new JTextField();
textField.setHorizontalAlignment(SwingConstants.CENTER);
textField.setForeground(new Color(138, 43, 226));
textField.setFont(new Font("微软雅黑", Font.BOLD, 27));
textField.setBounds(131, 13, 135, 101);
contentPane.add(textField);
textField.setColumns(10);

label = new JLabel("\u59D3\u540D\u663E\u793A");
label.setBackground(new Color(255, 20, 147));
label.setForeground(Color.YELLOW);
label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
label.setBounds(159, 127, 88, 36);
contentPane.add(label);
}

public void read() {
try {
f = new File(File);
if (!f.exists()) {
f.createNewFile();
}
fr = new FileReader(f);
br = new BufferedReader(fr);
String str = br.readLine();
while (str != null) {
names.add(str);
str = br.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}

}

public void write() {
read();
int index = (int) (Math.random() * names.size());
strName = names.get(index);

}
public void text(){


}
}