/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javafxapplication3;
import java.awt.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.regex.Pattern;
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.CellEditEvent;
import javafx.scene.control.TableView;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
public class Main extends Application {
//匹配姓名
private final String isChinese ="^[赵,钱,孙,李,周,吴,郑,王,冯,陈,楮,卫,蒋,沈,韩,杨,朱,秦,尤,许,何,吕,施,张,孔,曹,严,华,金,魏,陶,\"\n" +
" + \"姜,戚,谢,邹,喻,柏,水,窦,章,云,苏,潘,葛,奚,范,彭,郎,鲁,韦,昌,马,苗,凤,花,方,俞,任,袁,柳,酆,鲍,史,唐,费,廉,岑,薛,雷,贺,倪,汤,滕,殷,罗,\"\n" +
" + \"毕,郝,邬,安,常,乐,于,时,傅,皮,卞,齐,康,伍,余,元,卜,顾,孟,平,黄,和,穆,萧,尹,姚,邵,湛,汪,祁,毛,禹,狄,米,贝,明,臧,计,伏,成,戴,谈,宋,茅,\"\n" +
" + \"庞,熊,纪,舒,屈,项,祝,董,梁,杜,阮,蓝,闽,席,季,麻,强,贾,路,娄,危,江,童,颜,郭,梅,盛,林,刁,锺,徐,丘,骆,高,夏,蔡,田,樊,胡,凌,霍,虞,万,支,\"\n" +
" + \"柯,昝,管,卢,莫,经,房,裘,缪,干,解,应,宗,丁,宣,贲,邓,郁,单,杭,洪,包,诸,左,石,崔,吉,钮,龚,程,嵇,邢,滑,裴,陆,荣,翁,荀,羊,於,惠,甄,麹,家,\"\n" +
" + \"封,芮,羿,储,靳,汲,邴,糜,松,井,段,富,巫,乌,焦,巴,弓,牧,隗,山,谷,车,侯,宓,蓬,全,郗,班,仰,秋,仲,伊,宫,宁,仇,栾,暴,甘,斜,厉,戎,祖,武,符,\"\n" +
" + \"刘,景,詹,束,龙,叶,幸,司,韶,郜,黎,蓟,薄,印,宿,白,怀,蒲,邰,从,鄂,索,咸,籍,赖,卓,蔺,屠,蒙,池,乔,阴,郁,胥,能,苍,双,闻,莘,党,翟,谭,贡,劳,\"\n" +
" + \"逄,姬,申,扶,堵,冉,宰,郦,雍,郤,璩,桑,桂,濮,牛,寿,通,边,扈,燕,冀,郏,浦,尚,农,温,别,庄,晏,柴,瞿,阎,充,慕,连,茹,习,宦,艾,鱼,容,向,古,易,\"\n" +
" + \"慎,戈,廖,庾,终,暨,居,衡,步,都,耿,满,弘,匡,国,文,寇,广,禄,阙,东,欧,殳,沃,利,蔚,越,夔,隆,师,巩,厍,聂,晁,勾,敖,融,冷,訾,辛,阚,那,简,饶,\"\n" +
" + \"空,曾,毋,沙,乜,养,鞠,须,丰,巢,关,蒯,相,查,后,荆,红,游,竺,权,逑,盖,益,桓,公,万俟,司马,上官,欧阳,夏侯,诸葛,闻人,东方,赫连,皇甫,尉迟,\"\n" +
" + \"公羊,澹台,公冶,宗政,濮阳,淳于,单于,太叔,申屠,公孙,仲孙,轩辕,令狐,锺离,宇文,长孙,慕容,鲜于,闾丘,司徒,司空,丌官,司寇,仉,督,子车,\"\n" +
" + \"颛孙,端木,巫马,公西,漆雕,乐正,壤驷,公良,拓拔,夹谷,宰父,谷梁,晋,楚,阎,法,汝,鄢,涂,钦,段干,百里,东郭,南门,呼延,归,海,羊舌,微生,岳,\"\n" +
" + \"帅,缑,亢,况,后,有,琴,梁丘,左丘,东门,西门,商,牟,佘,佴,伯,赏,南宫,墨,哈,谯,笪,年,爱,阳,佟,第五,言,福][\\u4e00-\\u9fa5]{1,4}$";
//匹配邮件地址
private final String isEmail = "^[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$";
//匹配电话号码
private final String isPhoneNumber = "(^((13[0-9])|(14[0-9])|(15[0-9])|(17[0-9])|(18[0-9]))\\d{8}$)";
private final TableView<Person> table = new TableView<>(); //创建表格的整体框架
final HBox hb = new HBox(); //横向布局模型
private final ObservableList<Person> data =
FXCollections.observableArrayList(); // 表格显示数据
private final ObservableList<Person> tempData =
FXCollections.observableArrayList(); //替换表格,用于显示搜索的内容
//检查表格的类容是否受到修改
private Boolean saveFlag = true;
//检查输入是否合法的提示图片
private Image image1 = new Image("file:E:\\Users\\admin\\IdeaProjects\\JavaFXApplication3\\src\\javafxapplication3\\zhengque.png");
private Image image2 = new Image("file:E:\\Users\\admin\\IdeaProjects\\JavaFXApplication3\\src\\javafxapplication3\\cuowu.png");
//从文件中读入数据
public void getInfo(String path){
File file = new File(path);
Boolean boo = file.exists()&&file.isFile();
if(boo){
BufferedReader buf = null;
try{
buf = new BufferedReader(new FileReader(file));
String linetext = null;
int i = 0;
while((linetext = buf.readLine())!=null){
String[] b=linetext.split(" ");
//从文件读取每一行的数据到一个对象p中
Person p = new Person(b[0],b[1],b[2],b[3]);
//添加对象数组p到表格中,显示数据
data.add(p);
}
}catch (Exception e) {
System.out.println("读取文件内容出错");
e.printStackTrace();
}finally {
try {
buf.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}else{
System.out.println("找不到指定的文件");
}
}
//保存数据到文件
public void saveData(String path){
File f = new File(path);
try {
f.createNewFile();
}
catch(IOException e){
System.out.println(e);
}
BufferedWriter buf = null;
try{
buf = new BufferedWriter(new FileWriter(f));
int size = data.size();
for( int i = 0;i < size;i++){
buf.write(data.get(i).getName()+ " " + data.get(i).getAddres()+ " "
+ data.get(i).getEmail() + " " +data.get(i).getPhoneNumber() +"\n");
}
}catch (Exception e) {
System.out.println("读取文件内容出错");
e.printStackTrace();
}finally {
try {
buf.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
//交互界面提示消息
public void newStage(String Info){
Stage secondaryStage=new Stage();
//模态窗口,必须关闭当前提示框才能进行其它操作
secondaryStage.initModality(Modality.APPLICATION_MODAL);
final Label lable = new Label(Info);
lable.setAlignment(Pos.CENTER);
lable.setStyle("-fx-font-size:20;-fx-text-fill:red");
lable.setPadding(new Insets(30,0,10,0));
StackPane text = new StackPane();
text.getChildren().add(lable);
VBox vb = new VBox();
HBox hb = new HBox();
Button confirm = new Button("确�
评论0