实现数据库的连接,动态增、删、改、查功能 具体要求:1、实现一个小型通讯录 2、能够实现个人通讯录列表的显示,表格显示 3、能够实现通讯录信息的动态增加、修改和删除 4、多个账号登录后通讯录列表独立

//javafx选用jdk8
import java.sql.*;
import java.io.*;
import java.security.acl.Group;
import javafx.application.*;
import javafx.beans.value.*;
import javafx.collections.*;
import javafx.geometry.*;
import javafx.scene.Scene;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javafx.scene.text.*;
import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.layout.*;
public class Java extends Application
{
	private static TextField tf=new TextField();
	private PasswordField pf=new PasswordField();
	private static String driver="com.mysql.cj.jdbc.Driver";
	private static String url="jdbc:mysql://localhost:3306/test?serverTimezone=UTC";
	private static String user="root";
	Connection conn=null;
	PreparedStatement ps=null;
	ResultSet rs=null;
	private static String password="123456";
	@Override
	public void start(Stage stage)
	{
		final Label username=new Label("用户名:");
		final Label userpassword=new Label("密  码:");
		final Button login=new Button("登录");
		final Button enroll=new Button("注册");
		enroll.setOnAction(e->{
			Enroll enr=new Enroll();
			enr.start(new Stage());
			stage.hide();
		});
		enroll.setTranslateX(-60);
		login.setTranslateX(80);
		StackPane spane=new StackPane();
		Text text=new Text("欢迎进入通讯录");
		text.setFont(new Font("黑体",20));
		text.setTranslateY(80);
		spane.getChildren().add(text);
		tf.setPromptText("电话/用户名");
		pf.setPromptText("请输入密码");
		GridPane gpane=new GridPane();
		gpane.setHgap(10);
		gpane.setVgap(15);
		gpane.setAlignment(Pos.CENTER);
		gpane.add(username, 0, 0);
		gpane.add(tf, 1, 0);
		gpane.add(userpassword, 0, 1);
		gpane.add(pf, 1, 1);
		gpane.add(login, 1, 2);
		gpane.add(enroll, 2, 2);
		BorderPane bpane=new BorderPane();
		bpane.setTop(spane);
		Alert alert=new Alert(AlertType.INFORMATION);
		alert.setTitle("错误");
		alert.setHeaderText(null);
		bpane.setCenter(gpane);
		login.setOnAction(e->{
			if(tf.getText().equals("")||pf.getText().equals("")) {
				alert.setContentText("用户和密码字段不能为空!");
				alert.showAndWait();
			}else {
				String selectsql="select users from user;";
				String selectsql1="select upassword from user where users=?";
				try {
					Class.forName(driver);
					conn=DriverManager.getConnection(url,user,password);
					ps=conn.prepareStatement(selectsql);
					rs=ps.executeQuery();
					boolean bool=true;
					while(rs.next()) {
						if(tf.getText().equals(rs.getString("users"))) {
							ps=conn.prepareStatement(selectsql1);
							ps.setString(1, tf.getText());
							rs=ps.executeQuery();
							while(rs.next()) {
								if(pf.getText().equals(rs.getString("upassword"))) {
									Communication comm=new Communication();
									comm.USER=tf.getText();
									comm.start(new Stage());
									tf.setText("");
									stage.hide();
								}else {
									alert.setContentText("密码错误!");
									alert.showAndWait();
									pf.setText("");
									break;
								}
							}
					}else {
						bool=false;
					}
				}
				if(bool=false) {
					alert.setContentText("请先注册!");
					alert.showAndWait();
				}
			}catch(Exception ex) {
				ex.toString();
			}
		}});
		Scene scene=new Scene(bpane,500,400);
		stage.setTitle("登录");
		stage.setScene(scene);
		stage.show();
	}
}
class Communication extends Application
{
	public static String USER;
	@Override
	public void start(Stage stage)
	{
		Text t=new Text(USER);
		USER=t.getText();
		Java java=new Java();
		BorderPane bpane=new BorderPane();
		final Button add=new Button("添加好友到通讯录中");
		add.setOnAction(e->{
			AddFriend addf=new AddFriend();
			addf.username=t.getText();
			addf.start(new Stage());
			stage.hide();
		});
		final Button del=new Button("将好友从通讯录删除");
		del.setOnAction(e->{
			DelFriend delf=new DelFriend();
			delf.User=t.getText();
			delf.start(new Stage());
			stage.close();
		});
		final Button update =new Button("修改通讯录好友信息");
		update.setOnAction(e->{
			UpdateFriend upf=new UpdateFriend();
			upf.User=t.getText();
			upf.start(new Stage());
			stage.close();
		});
		final Button find=new Button("从通讯录中查询好友");
		find.setOnAction(e->{
			FindFriend findf=new FindFriend();
			findf.User=t.getText();
			findf.start(new Stage());
			stage.close();
		});
		final Button output=new Button("导出通讯录好友信息");
		output.setOnAction(e->{
			Output op=new Output();
			op.User=t.getText();
			op.start(new Stage());
			stage.close();
		});
		Label lab=new Label("用户:");
		t.setTranslateX(-40);
		Button manager=new Button("管理账号");
		HBox hb=new HBox(50);
		hb.setTranslateX(380);
		manager.setTranslateX(170);
		manager.setTranslateY(-40);
		hb.setTranslateY(-40);
		hb.getChildren().addAll(lab,t);
		VBox vb=new VBox(10);
		vb.setAlignment(Pos.CENTER);
		Text te=new Text("请从下列选项中选择您需要的操作");
		te.setFont(new Font("黑体",20));
		te.setTranslateY(-30);
		vb.getChildren().addAll(hb,manager,te,add,del,update,find,output);
		bpane.setCenter(vb);
		manager.setOnAction(e->{
			Manager m=new Manager();
			m.User=t.getText();
			m.start(new Stage());
		});
		Scene scene=new Scene(bpane,500,400);
		stage.setScene(scene);
		stage.setTitle("通讯录");
		stage.show();
	}
}
class Manager extends Application
{
	public static String User;
	private static String driver="com.mysql.cj.jdbc.Driver";
	private static String url="jdbc:mysql://localhost:3306/test?serverTimezone=UTC";
	private static String user="root";
	private static String password="123456";
	@Override
	public void start(Stage stage)
	{
		Alert alert=new Alert(AlertType.INFORMATION);
		alert.setTitle("提示");
		alert.setHeaderText(null);
		Label lab1=new Label("修改密码");
		lab1.setFont(new Font("黑体",17));
		Label lab2=new Label("原密码:");
		lab2.setFont(new Font("黑体",15));
		Label lab3=new Label("新密码:");
		lab3.setFont(new Font("黑体",15));
		Label lab4=new Label("电话更改");
		lab4.setFont(new Font("黑体",17));
		Label lab5=new Label("原电话:");
		lab5.setFont(new Font("黑体",15));
		Label lab6=new Label("新电话:");
		lab6.setFont(new Font("黑体",15));
		PasswordField oldpf=new PasswordField();
		PasswordField newpf=new PasswordField();
		TextField oldtf=new TextField();
		TextField newtf=new TextField();
		oldpf.setPromptText("请输入原密码");
		newpf.setPromptText("请输入新密码");
		oldtf.setPromptText("请输入旧的电话号码");
		newtf.setPromptText("请输入新的电话号码");
		Label lab7=new Label("账号管理:");
		lab7.setFont(new Font("黑体",17));
		Button but1=new Button("切换账号");
		Button but2=new Button("退出登录");
		HBox hb1=new HBox(10);
		hb1.getChildren().addAll(lab2,oldpf);
		HBox hb2=new HBox(10);
		hb2.getChildren().addAll(lab3,newpf);
		VBox vb1=new VBox(10);
		vb1.getChildren().addAll(hb1,hb2);
		HBox hb3=new HBox(10);
		hb3.getChildren().addAll(lab5,oldtf);
		HBox hb4=new HBox(10);
		hb4.getChildren().addAll(lab6,newtf);
		VBox vb2=new VBox(10);
		vb2.getChildren().addAll(hb3,hb4);
		vb1.setTranslateX(20);
		vb2.setTranslateX(20);
		HBox hb5=new HBox(20);
		hb5.getChildren().addAll(but1,but2);
		hb5.setTranslateX(-170);
		Button save=new Button("保存");
		Button cannel =new Button("取消");
		HBox hb=new HBox(20);
		hb.getChildren().addAll(save,cannel);
		GridPane gpane=new GridPane();
		gpane.add(lab1, 0, 0);
		gpane.add(vb1, 0, 1);
		gpane.add(lab4, 0, 2);
		gpane.add(vb2, 0, 3);
		gpane.add(lab7, 0, 4);
		gpane.add(hb5, 1, 4);
		gpane.add(hb, 1, 7);
		gpane.setAlignment(Pos.CENTER);
		gpane.setTranslateX(70);
		gpane.setVgap(10);
		String select="select upassword,usertelephone from user where users=?";
		String updatepf="update user set upassword=? where users=?";
		String updatetf="update user set usertelephone=? where users=?";
		save.setOnAction(e->{
			try {
				Connection conn=DriverManager.getConnection(url,user,password);
				PreparedStatement ps=conn.prepareStatement(select);
				Class.forName(driver);
				ps.setString(1, User);
				ResultSet rs=ps.executeQuery();
				while(rs.next()) {
					String strpassword=rs.getString("upassword");
					String strteltephone=rs.getString("usertelephone");
					if(oldpf.getText().length()>1) {
						if(oldpf.getText().equals(strpassword)) {
							ps=conn.prepareStatement(updatepf);
							ps.setString(1,newpf.getText());
							ps.setString(2, User);
							ps.executeUpdate();
							alert.setContentText("密码修改成功!");
							alert.showAndWait();
							oldpf.setText("");
							newpf.setText("");
							break;
						}else {
							alert.setContentText("原密码错误,请重新输入!");
							alert.showAndWait();
							oldpf.setText("");
							break;
						}
					}if(oldtf.getText().length()==11) {
						if(oldtf.getText().equals(strteltephone)) {
							ps=conn.prepareStatement(updatetf);
							ps.setString(1,newtf.getText());
							ps.setString(2, User);
							ps.executeUpdate();
							alert.setContentText("电话修改成功!");
							alert.showAndWait();
							oldtf.setText("");
							newtf.setText("");
							break;
						}else {
							alert.setContentText("原号码错误,请重新输入!");
							alert.showAndWait();
							oldpf.setText("");
							break;
						}	
					}if(oldpf.getText()==null&&newpf.getText()==null&&oldtf.getText()==null&&newtf.getText()==null) {
						alert.setContentText("修改的内容不能为空!");
						alert.showAndWait();
					}
				}
				
			}catch(Exception ex) {
				ex.printStackTrace();
			}
		});
		cannel.setOnAction(e->{
			stage.close();
		});
		but1.setOnAction(e->{
			Java java=new Java();
			java.start(new Stage());
		});
		but2.setOnAction(e->{
			Platform.exit();
		});
		stage.setTitle(User);
		StackPane stack=new StackPane();
		stack.getChildren().add(gpane);
		Scene scene=new Scene(stack,500,400);
		stage.setScene(scene);
		stage.show();
	}
}
class AddFriend extends Application
{
	private static String driver="com.mysql.cj.jdbc.Driver";
	private static String url="jdbc:mysql://localhost:3306/test?serverTimezone=UTC";
	private static String user="root";
	private static String password="123456";
	public  static String username;
	private static String GroupRadioButton;
	private static String GroupSex;
	private static String str=" ";
	@SuppressWarnings("resource")
	@Override
	public void start(Stage stage)
	{
		StackPane spane=new StackPane();
		spane.setAlignment(Pos.CENTER);
		spane.setPadding(new Insets(30));
		Label name=new Label("姓名:");
		Label group=new Label("分组:");
		Label sex=new Label("性别:");
		Label age=new Label("年龄:");
		TextField tname=new TextField();
		RadioButton familyers=new RadioButton("家人");
		RadioButton colleague=new RadioButton("同事");
		RadioButton schoolmate=new RadioButton("同学");
		RadioButton teacher=new RadioButton("老师");
		RadioButton friend=new RadioButton("朋友");
		ToggleGroup toggroup=new ToggleGroup();
		familyers.setToggleGroup(toggroup);
		colleague.setToggleGroup(toggroup);
		schoolmate.setToggleGroup(toggroup);
		teacher.setToggleGroup(toggroup);
		friend.setToggleGroup(toggroup);
		HBox hbgroup=new HBox(10);
		hbgroup.getChildren().addAll(group,familyers,colleague,schoolmate,teacher,friend);
		RadioButton boy=new RadioButton("男");
		RadioButton girl=new RadioButton("女");
		ToggleGroup tog=new ToggleGroup();
		boy.setToggleGroup(tog);
		girl.setToggleGroup(tog);
		HBox hbname=new HBox(10);
		HBox hbsex=new HBox(10);
		hbname.getChildren().addAll(name,tname);
		hbsex.getChildren().addAll(sex,boy,girl);
		VBox vb=new VBox(10);
		Slider slider=new Slider();
		Text tage=new Text("0");
		slider.setMin(1);
		slider.setMax(100);
		slider.setShowTickLabels(true);
		slider.setShowTickMarks(true);
		slider.valueProperty().addListener(ov->{
			double value=slider.getValue();
			int valu=(int)value;
			String strs=String.valueOf(valu);
			tage.setText(strs);
		});
		slider.setPrefWidth(200);
		HBox hbage=new HBox(10);
		hbage.getChildren().addAll(age,slider,tage);
		Label telephone=new Label("电话:");
		TextField ttel=new TextField();
		HBox hbtelephone=new HBox(10);
		hbtelephone.getChildren().addAll(telephone,ttel);
		Label mail=new Label("邮箱:");
		TextField tmail=new TextField();
		HBox hbmail=new HBox(10);
		hbmail.getChildren().addAll(mail,tmail);
		Label Lcity=new Label("现居住城市:");
		ComboBox<String>cbo=new ComboBox<String>();
		String[] city= {"北京市","上海市","广州市	","深圳市","天津市","成都市","杭州市","苏州市","重庆市","武汉市","南京市","大连市","沈阳市","长沙市","郑州市","西安市","青岛市","无锡市","无锡市","宁波市","佛山市","南通市","哈尔滨市","东莞市","福州市","长春市","石家庄市","烟台市","合肥市","唐山市","常州市","太原市","昆明市","潍坊市","南昌市","泉州市","温州市","绍兴市","嘉兴市","厦门市","贵阳市","淄博市","徐州市","扬州市","呼和浩特市","鄂尔多斯市","乌鲁木齐市","金华市","台州市","镇江市","威海市","珠海市","东营市","大庆市","中山市","盐城市","包头市","保定市","济宁市","兰州市"};
		ObservableList<String>items=FXCollections.observableArrayList(city);
		cbo.getItems().addAll(items);
		cbo.setPrefWidth(130);
		cbo.setValue("请选择城市");
		HBox hbcity=new HBox(10);
		hbcity.getChildren().addAll(Lcity,cbo);
		Label hobby=new Label("爱好:");
		CheckBox cb1=new CheckBox("球类运动");
		CheckBox cb2=new CheckBox("文学阅读");
		CheckBox cb3=new CheckBox("文学创造");
		CheckBox cb4=new CheckBox("听音乐");
		CheckBox cb5=new CheckBox("看电影");
		CheckBox cb6=new CheckBox("绘画");
		CheckBox cb7=new CheckBox("舞蹈");
		CheckBox cb8=new CheckBox("冒险");
		CheckBox cb9=new CheckBox("收藏");
		CheckBox cb10=new CheckBox("网络游戏");
		CheckBox cb11=new CheckBox("喝茶");
		CheckBox cb12=new CheckBox("探索");
		VBox vb1=new VBox(10);
		VBox vb2=new VBox(10);
		VBox vb3=new VBox(10);
		VBox vb4=new VBox(10);
		vb1.getChildren().addAll(cb1,cb2,cb3);
		vb2.getChildren().addAll(cb4,cb5,cb6);
		vb3.getChildren().addAll(cb7,cb8,cb9);
		vb4.getChildren().addAll(cb10,cb11,cb12);
		HBox hb=new HBox(10);
		hb.getChildren().addAll(hobby,vb1,vb2,vb3,vb4);
		TextArea ta=new TextArea();
		Text tevent=new Text("记录你我之间的每一份美好");
		ta.setPromptText("记录你我的点滴");
		ta.setPrefHeight(200);
		ta.setWrapText(true);
		Button save=new Button("添加");
		save.setTranslateX(100);
		save.setPrefWidth(300);
		save.setPrefHeight(30);
		save.setFont(new Font("黑体",16));
		Label remark=new Label("备注:");
		TextField tremark=new TextField();
		HBox hbremark=new HBox(10);
		hbremark.getChildren().addAll(remark,tremark);
		Button exit=new Button("取消");
		exit.setTranslateX(100);
		exit.setPrefHeight(30);
		HBox hbo=new HBox(10);
		hbo.getChildren().addAll(save,exit);
		exit.setOnAction(e->{
			Communication comm=new Communication();
			comm.start(new Stage());
			stage.close();
		});
		vb.getChildren().addAll(hbname,hbgroup,hbsex,hbage,hbtelephone,hbmail,hbcity,hb,hbremark,tevent,ta,hbo);
		spane.getChildren().add(vb);
		stage.setTitle("添加好友到通讯录中");
		toggroup.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
	           @Override
	           public void changed(ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) {
	               if (toggroup.getSelectedToggle() != null) {
	                   RadioButton button = (RadioButton) toggroup.getSelectedToggle();
	                   GroupRadioButton=button.getText();
	               }
	           }
	       });
		tog.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
	           @Override
	           public void changed(ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) {
	               if (tog.getSelectedToggle() != null) {
	                   RadioButton button = (RadioButton) tog.getSelectedToggle();
	                   GroupSex=button.getText();
	               }
	           }
	       });
		cb1.setOnAction(e->{str+=cb1.getText()+"、";});
		cb2.setOnAction(e->{str+=cb2.getText()+"、";});
		cb3.setOnAction(e->{str+=cb3.getText()+"、";});
		cb4.setOnAction(e->{str+=cb4.getText()+"、";});
		cb5.setOnAction(e->{str+=cb5.getText()+"、";});
		cb6.setOnAction(e->{str+=cb6.getText()+"、";});
		cb7.setOnAction(e->{str+=cb7.getText()+"、";});
		cb8.setOnAction(e->{str+=cb8.getText()+"、";});
		cb9.setOnAction(e->{str+=cb9.getText()+"、";});
		cb10.setOnAction(e->{str+=cb10.getText()+"、";});
		cb11.setOnAction(e->{str+=cb11.getText()+"、";});
		cb12.setOnAction(e->{str+=cb12.getText()+"、";});
		Alert alert=new Alert(AlertType.INFORMATION);
		alert.setTitle("提示");
		alert.setHeaderText(null);
		save.setOnAction(e->{
			Connection conn=null;
			PreparedStatement ps=null;
			String insertcomm="insert into Communication values(?,?,?,?,?,?,?,?,?,?);";
			String insertclass="insert into Classification values(?,?,?);";
			if(tname.getText()!=null&&GroupSex!=null&&tage.getText()!=null&&ttel.getText()!=null) {
				try {
					Class.forName(driver);
					conn=DriverManager.getConnection(url,user,password);
					ps=conn.prepareStatement(insertcomm);
					ps.setString(1, username);
					ps.setString(2, tname.getText());
					ps.setString(3, GroupSex);
					int fage=Integer.parseInt(tage.getText());
					ps.setInt(4, fage);
					ps.setString(5, ttel.getText());
					ps.setString(6, tmail.getText());
					ps.setString(7, cbo.getValue());
					ps.setString(8, str);
					ps.setString(9, tremark.getText());
					ps.setString(10, ta.getText());
					ps.executeUpdate();
					alert.setContentText("好友添加成功");
					alert.showAndWait();
					ps=conn.prepareStatement(insertclass);
					ps.setString(1, tname.getText());
					ps.setString(2, GroupRadioButton);
					ps.setString(3, ttel.getText());
					ps.executeUpdate();
					stage.close();
					Communication comm=new Communication();
					comm.start(new Stage());
				}catch(Exception ex) {
					ex.printStackTrace();
				}finally {
					try {
						if(ps!=null)ps.close();
						if(conn!=null)conn.close();
					}catch(Exception ex) {
						ex.printStackTrace();
					}
				}
			}else {
				alert.setContentText("好友信息不能为空");
				alert.showAndWait();
			}
		});
		Scene scene=new Scene(spane,600,700);
		stage.setScene(scene);
		stage.show();	
	}
}
class DelFriend extends Application
{
	public static String User;
	private static String driver="com.mysql.cj.jdbc.Driver";
	private static String url="jdbc:mysql://localhost:3306/test?serverTimezone=UTC";
	private static String user="root";
	private static String password="123456";
	@Override
	public void start(Stage stage)
	{
		Text t=new Text("请输入您要删除的好友的姓名");
		t.setFont(new Font("黑体",18));
		Label lab=new Label("姓名:");
		TextField text=new TextField();
		Button button=new Button("删除");
		button.setPrefWidth(100);
		Button cannel=new Button("取消");
		cannel.setOnAction(e->{
			Communication comm=new Communication();
			comm.start(new Stage());
			stage.close();
		});
		HBox deca=new HBox(20);
		deca.getChildren().addAll(button,cannel);
		deca.setTranslateY(-150);
		deca.setTranslateX(20);
		deca.setAlignment(Pos.CENTER);
		StackPane spane=new StackPane();
		spane.setPadding(new Insets(100));
		spane.getChildren().add(t);
		HBox hb=new HBox(10);
		hb.setTranslateY(-120);
		hb.setAlignment(Pos.CENTER);
		hb.getChildren().addAll(lab,text);
		BorderPane bpane=new BorderPane();
		bpane.setTop(spane);
		bpane.setCenter(hb);
		bpane.setBottom(deca);
		Alert alert=new Alert(AlertType.INFORMATION);
		alert.setTitle("错误");
		alert.setHeaderText(null);
		button.setOnAction(e->{
			String selectsql="select cName from Communication where users=?;";
			Connection conn=null;
			PreparedStatement ps=null;
			ResultSet rs=null;
			try {
				Class.forName(driver);
				conn=DriverManager.getConnection(url,user,password);
				ps=conn.prepareStatement(selectsql);
				ps.setString(1, User);
				rs=ps.executeQuery();
				if(text.getText()!=null) {
					while(rs.next()) {
						if(text.getText().equals(rs.getString("cName"))) {
							String name=text.getText();
							String deletesql="delete from Communication where cName=?;";
							String delete="delete from Classification where cName=?;";
							try {
								ps=conn.prepareStatement(deletesql);
								ps.setString(1, name);
								ps.executeUpdate();
								ps=conn.prepareStatement(delete);
								ps.setString(1,name);
								ps.executeUpdate();
								alert.setContentText(name+"已从您的通讯录中成功删除!");
								alert.showAndWait();
								Communication comm=new Communication();
								comm.start(new Stage());
							}catch(Exception ex) {
								ex.printStackTrace();
							}
						}
					}
				}else {
					alert.setContentText("请输入您要删除的好友的姓名!");
					alert.showAndWait();
				}
			}catch(Exception ex) {
				ex.printStackTrace();
			}
		});
		Scene scene=new Scene(bpane,500,400);
		stage.setTitle("将好友从通讯录中删除");
		stage.setScene(scene);
		stage.show();
	}
}
class UpdateFriend extends Application
{
	public static String User;
	private static String driver="com.mysql.cj.jdbc.Driver";
	private static String url="jdbc:mysql://localhost:3306/test?serverTimezone=UTC";
	private static String user="root";
	private static String password="123456";
	private static String GroupRadioButton;
	private static String GroupSex;
	private static String str="";
	@SuppressWarnings({ "resource", "unused" })
	@Override
	public void start(Stage stage)
	{
		Alert alert=new Alert(AlertType.INFORMATION);
		alert.setTitle("提示");
		alert.setHeaderText(null);
		String u=User;
		Text t=new Text("请先调出您要修改的好友");
		t.setFont(new Font("黑体",20));
		StackPane stack=new StackPane();
		TextField te=new TextField();
		Label queryname=new Label("姓名:");
		Button button=new Button("查询");
		HBox hbox=new HBox(10);
		hbox.getChildren().addAll(queryname,te,button);
		hbox.setTranslateX(70);
		hbox.setTranslateY(50);
		stack.getChildren().addAll(t,hbox);
		stack.setPadding(new Insets(40));
		stack.setTranslateY(-30);
		StackPane spane=new StackPane();
		spane.setAlignment(Pos.CENTER);
		spane.setPadding(new Insets(30));
		Label name=new Label("姓名:");
		Label group=new Label("分组:");
		Label sex=new Label("性别:");
		Label age=new Label("年龄:");
		TextField tname=new TextField();
		RadioButton familyers=new RadioButton("家人");
		RadioButton colleague=new RadioButton("同事");
		RadioButton schoolmate=new RadioButton("同学");
		RadioButton teacher=new RadioButton("老师");
		RadioButton friend=new RadioButton("朋友");
		ToggleGroup toggroup=new ToggleGroup();
		familyers.setToggleGroup(toggroup);
		colleague.setToggleGroup(toggroup);
		schoolmate.setToggleGroup(toggroup);
		teacher.setToggleGroup(toggroup);
		friend.setToggleGroup(toggroup);
		HBox hbgroup=new HBox(10);
		hbgroup.getChildren().addAll(group,familyers,colleague,schoolmate,teacher,friend);
		RadioButton boy=new RadioButton("男");
		RadioButton girl=new RadioButton("女");
		ToggleGroup tog=new ToggleGroup();
		boy.setToggleGroup(tog);
		girl.setToggleGroup(tog);
		HBox hbname=new HBox(10);
		HBox hbsex=new HBox(10);
		hbname.getChildren().addAll(name,tname);
		hbsex.getChildren().addAll(sex,boy,girl);
		VBox vb=new VBox(10);
		Slider slider=new Slider();
		Text tage=new Text("0");
		slider.setMin(1);
		slider.setMax(100);
		slider.setShowTickLabels(true);
		slider.setShowTickMarks(true);
		slider.valueProperty().addListener(ov->{
			double value=slider.getValue();
			int valu=(int)value;
			String strs=String.valueOf(valu);
			tage.setText(strs);
		});
		slider.setPrefWidth(200);
		HBox hbage=new HBox(10);
		hbage.getChildren().addAll(age,slider,tage);
		Label telephone=new Label("电话:");
		TextField ttel=new TextField();
		HBox hbtelephone=new HBox(10);
		hbtelephone.getChildren().addAll(telephone,ttel);
		Label mail=new Label("邮箱:");
		TextField tmail=new TextField();
		HBox hbmail=new HBox(10);
		hbmail.getChildren().addAll(mail,tmail);
		Label Lcity=new Label("现居住城市:");
		ComboBox<String>cbo=new ComboBox<String>();
		String[] city= {"北京市","上海市","广州市	","深圳市","天津市","成都市","杭州市","苏州市","重庆市","武汉市","南京市","大连市","沈阳市","长沙市","郑州市","西安市","青岛市","无锡市","无锡市","宁波市","佛山市","南通市","哈尔滨市","东莞市","福州市","长春市","石家庄市","烟台市","合肥市","唐山市","常州市","太原市","昆明市","潍坊市","南昌市","泉州市","温州市","绍兴市","嘉兴市","厦门市","贵阳市","淄博市","徐州市","扬州市","呼和浩特市","鄂尔多斯市","乌鲁木齐市","金华市","台州市","镇江市","威海市","珠海市","东营市","大庆市","中山市","盐城市","包头市","保定市","济宁市","兰州市"};
		ObservableList<String>items=FXCollections.observableArrayList(city);
		cbo.getItems().addAll(items);
		cbo.setPrefWidth(130);
		cbo.setValue("请选择城市");
		HBox hbcity=new HBox(10);
		hbcity.getChildren().addAll(Lcity,cbo);
		Label hobby=new Label("爱好:");
		CheckBox cb1=new CheckBox("球类运动");
		CheckBox cb2=new CheckBox("文学阅读");
		CheckBox cb3=new CheckBox("文学创造");
		CheckBox cb4=new CheckBox("听音乐");
		CheckBox cb5=new CheckBox("看电影");
		CheckBox cb6=new CheckBox("绘画");
		CheckBox cb7=new CheckBox("舞蹈");
		CheckBox cb8=new CheckBox("冒险");
		CheckBox cb9=new CheckBox("收藏");
		CheckBox cb10=new CheckBox("网络游戏");
		CheckBox cb11=new CheckBox("喝茶");
		CheckBox cb12=new CheckBox("探索");
		VBox vb1=new VBox(10);
		VBox vb2=new VBox(10);
		VBox vb3=new VBox(10);
		VBox vb4=new VBox(10);
		vb1.getChildren().addAll(cb1,cb2,cb3);
		vb2.getChildren().addAll(cb4,cb5,cb6);
		vb3.getChildren().addAll(cb7,cb8,cb9);
		vb4.getChildren().addAll(cb10,cb11,cb12);
		HBox hb=new HBox(10);
		hb.getChildren().addAll(hobby,vb1,vb2,vb3,vb4);
		TextArea ta=new TextArea();
		Text tevent=new Text("记录你我之间的每一份美好");
		ta.setPromptText("记录你我的点滴");
		ta.setPrefHeight(200);
		ta.setWrapText(true);
		Button save=new Button("保存修改");
		Button cannel=new Button("取消");
		cannel.setOnAction(e->{
			stage.close();
			Communication comm=new Communication();
			comm.start(new Stage());
		});
		HBox hbo=new HBox(20);
		hbo.setTranslateX(100);
		hbo.getChildren().addAll(save,cannel);
		save.setPrefWidth(300);
		save.setPrefHeight(30);
		cannel.setPrefHeight(30);
		save.setFont(new Font("黑体",16));
		Label remark=new Label("备注:");
		TextField tremark=new TextField();
		HBox hbremark=new HBox(10);
		hbremark.getChildren().addAll(remark,tremark);
		vb.getChildren().addAll(stack,hbname,hbgroup,hbsex,hbage,hbtelephone,hbmail,hbcity,hb,hbremark,tevent,ta,hbo);
		spane.getChildren().add(vb);
		stage.setTitle("修改通讯录好友信息");
		toggroup.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
	           @Override
	           public void changed(ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) {
	               if (toggroup.getSelectedToggle() != null) {
	                   RadioButton button = (RadioButton) toggroup.getSelectedToggle();
	                   GroupRadioButton=button.getText();
	               }
	           }
	       });
		tog.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
	           @Override
	           public void changed(ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) {
	               if (tog.getSelectedToggle() != null) {
	                   RadioButton button = (RadioButton) tog.getSelectedToggle();
	                   GroupSex=button.getText();
	               }
	           }
	       });
		cb1.setOnAction(e->{str+=cb1.getText()+"、";});
		cb2.setOnAction(e->{str+=cb2.getText()+"、";});
		cb3.setOnAction(e->{str+=cb3.getText()+"、";});
		cb4.setOnAction(e->{str+=cb4.getText()+"、";});
		cb5.setOnAction(e->{str+=cb5.getText()+"、";});
		cb6.setOnAction(e->{str+=cb6.getText()+"、";});
		cb7.setOnAction(e->{str+=cb7.getText()+"、";});
		cb8.setOnAction(e->{str+=cb8.getText()+"、";});
		cb9.setOnAction(e->{str+=cb9.getText()+"、";});
		cb10.setOnAction(e->{str+=cb10.getText()+"、";});
		cb11.setOnAction(e->{str+=cb11.getText()+"、";});
		cb12.setOnAction(e->{str+=cb12.getText()+"、";});
		button.setOnAction(e->{
			try {
				Class.forName(driver);
				String selectsql="select cName from Communication where users=?";
				Connection con=DriverManager.getConnection(url,user,password);
				PreparedStatement ps=con.prepareStatement(selectsql);
				ps.setString(1, u);
				ResultSet rs=ps.executeQuery();
				boolean bool=true;
				while(rs.next()) {
					if(te.getText().equals(rs.getString("cName"))) {
						String selectname=te.getText();
						String select="select Communication.*,Classification.sectionalization from Communication,Classification where Communication.telephone=classification.telephone and Communication.cName=?";
						ps=con.prepareStatement(select);
						ps.setString(1, selectname);
						rs=ps.executeQuery();
						while(rs.next()) {
							String sname=rs.getString("cName");
							String sgroup=rs.getString("sectionalization");
							String ssex=rs.getString("sex");
							int iage=rs.getInt("age");
							String sage=String.valueOf(iage);
							String stel=rs.getString("telephone");
							String smail=rs.getString("mailbox");
							String scity=rs.getString("city");
							String shobby=rs.getString("hobby");
							String sremark=rs.getString("remark");
							String sevent=rs.getString("cevent");
							tname.setText(sname);
							if(familyers.getText().equals(sgroup))
								familyers.setSelected(true);
							else if(colleague.getText().equals(sgroup))
								colleague.setSelected(true);
							else if(schoolmate.getText().equals(sgroup))
								schoolmate.setSelected(true);
							else if(teacher.getText().equals(sgroup))
								teacher.setSelected(true);
							else if(friend.getText().equals(sgroup))
								friend.setSelected(true);
							if(boy.getText().equals(ssex))
								boy.setSelected(true);
							else girl.setSelected(true);
							tage.setText(sage);
							slider.setValue(iage);
							ttel.setText(stel);
							tmail.setText(smail);
							cbo.setValue(scity);
							String[] hob=new String[12];
							int n=0;
							for(int i=0;shobby.length()>1;i++) {
								int index=shobby.indexOf("、");
								hob[i]=shobby.substring(0,index);
								n++;
								shobby=shobby.replace(shobby.substring(0,index+1), "");
							}
							for(int j=0;j<n;j++) {
								if(cb1.getText().equals(hob[j])) cb1.setSelected(true);
								if(cb2.getText().equals(hob[j])) cb2.setSelected(true);
								if(cb3.getText().equals(hob[j])) cb3.setSelected(true);
								if(cb4.getText().equals(hob[j])) cb4.setSelected(true);
								if(cb5.getText().equals(hob[j])) cb5.setSelected(true);
								if(cb6.getText().equals(hob[j])) cb6.setSelected(true);
								if(cb7.getText().equals(hob[j])) cb7.setSelected(true);
								if(cb8.getText().equals(hob[j])) cb8.setSelected(true);
								if(cb9.getText().equals(hob[j])) cb9.setSelected(true);
								if(cb10.getText().equals(hob[j])) cb10.setSelected(true);
								if(cb11.getText().equals(hob[j])) cb11.setSelected(true);
								if(cb12.getText().equals(hob[j])) cb12.setSelected(true);
							}
							tremark.setText(sremark);
							ta.setText(sevent);
							bool=true;
							break;
						}
					}else {
						bool=false;
					}
				}if(bool==false) {
					alert.setContentText("查无此人!");
					alert.showAndWait();
				}
			}catch(Exception ex) {
				ex.printStackTrace();
			}
		});
		save.setOnAction(e->{
			Connection conn=null;
			PreparedStatement ps=null;
			String uname=te.getText();
			String insertcomm="update Communication set users=?,cName=?,sex=?,age=?,telephone=?,mailbox=?,city=?,hobby=?,remark=?,cevent=? where cName=?;";
			String insertclass="update Classification set cName=?,sectionalization=?,telephone=? where cName=?;";
			if(te.getText().equals("")) {
				alert.setContentText("修改信息不能为空");
				alert.showAndWait();
			}
			else {
				try {
					Class.forName(driver);
					conn=DriverManager.getConnection(url,user,password);
					ps=conn.prepareStatement(insertcomm);
					ps.setString(1, u);
					ps.setString(2, tname.getText());
					ps.setString(3, GroupSex);
					int fage=Integer.parseInt(tage.getText());
					ps.setInt(4, fage);
					ps.setString(5, ttel.getText());
					ps.setString(6, tmail.getText());
					ps.setString(7, cbo.getValue());
					ps.setString(8, str);
					ps.setString(9, tremark.getText());
					ps.setString(10, ta.getText());
					ps.setString(11, uname);
					ps.executeUpdate();
					alert.setTitle("提示");
					alert.setContentText(te.getText()+"的信息已修改成功!");
					alert.showAndWait();
					ps=conn.prepareStatement(insertclass);
					ps.setString(1, tname.getText());
					ps.setString(2, GroupRadioButton);
					ps.setString(3, ttel.getText());
					ps.setString(4, uname);
					ps.executeUpdate();
					stage.close();
					Communication comm=new Communication();
					comm.start(new Stage());
				}catch(Exception ex) {
					ex.printStackTrace();
				}finally {
					try {
						if(ps!=null)ps.close();
						if(conn!=null)conn.close();
					}catch(Exception ex) {
						ex.printStackTrace();
					}
				}
			}	
		});
		Scene scene=new Scene(spane,600,800);
		stage.setScene(scene);
		stage.show();
	}
}
class FindFriend extends Application
{
	private static String driver="com.mysql.cj.jdbc.Driver";
	private static String url="jdbc:mysql://localhost:3306/test?serverTimezone=UTC";
	private static String user="root";
	private static String password="123456";
	public  static String User;
	private static String GroupRadioButton;
	private static String GroupSex;
	private static String str="";
	@Override
	public void start(Stage stage)
	{
		StackPane spane=new StackPane();
		spane.setAlignment(Pos.CENTER);
		spane.setPadding(new Insets(30));
		Label name=new Label("按姓名查询:");
		Label group=new Label("按分组查询:");
		Label sex=new Label("按性别查询:");
		Label age=new Label("按年龄查询:");
		TextField tname=new TextField();
		RadioButton familyers=new RadioButton("家人");
		RadioButton colleague=new RadioButton("同事");
		RadioButton schoolmate=new RadioButton("同学");
		RadioButton teacher=new RadioButton("老师");
		RadioButton friend=new RadioButton("朋友");
		ToggleGroup toggroup=new ToggleGroup();
		familyers.setToggleGroup(toggroup);
		colleague.setToggleGroup(toggroup);
		schoolmate.setToggleGroup(toggroup);
		teacher.setToggleGroup(toggroup);
		friend.setToggleGroup(toggroup);
		HBox hbgroup=new HBox(10);
		hbgroup.getChildren().addAll(group,familyers,colleague,schoolmate,teacher,friend);
		RadioButton boy=new RadioButton("男");
		RadioButton girl=new RadioButton("女");
		ToggleGroup tog=new ToggleGroup();
		boy.setToggleGroup(tog);
		girl.setToggleGroup(tog);
		HBox hbname=new HBox(10);
		HBox hbsex=new HBox(10);
		Button clear=new Button("重选");
		clear.setTranslateX(150);
		hbname.getChildren().addAll(name,tname,clear);
		hbsex.getChildren().addAll(sex,boy,girl);
		VBox vb=new VBox(10);
		TextField startage=new TextField();
		TextField endage=new TextField();
		startage.setPrefWidth(50);
		endage.setPrefWidth(50);
		HBox hbage=new HBox(10);
		Text t=new Text("—");
		hbage.getChildren().addAll(age,startage,t,endage);
		Label Lcity=new Label("按城市查询:");
		ComboBox<String>cbo=new ComboBox<String>();
		String[] city= {"北京市","上海市","广州市	","深圳市","天津市","成都市","杭州市","苏州市","重庆市","武汉市","南京市","大连市","沈阳市","长沙市","郑州市","西安市","青岛市","无锡市","无锡市","宁波市","佛山市","南通市","哈尔滨市","东莞市","福州市","长春市","石家庄市","烟台市","合肥市","唐山市","常州市","太原市","昆明市","潍坊市","南昌市","泉州市","温州市","绍兴市","嘉兴市","厦门市","贵阳市","淄博市","徐州市","扬州市","呼和浩特市","鄂尔多斯市","乌鲁木齐市","金华市","台州市","镇江市","威海市","珠海市","东营市","大庆市","中山市","盐城市","包头市","保定市","济宁市","兰州市"};
		ObservableList<String>items=FXCollections.observableArrayList(city);
		cbo.getItems().addAll(items);
		cbo.setPrefWidth(130);
		cbo.setValue("请选择城市");
		HBox hbcity=new HBox(10);
		hbcity.getChildren().addAll(Lcity,cbo);
		Label hobby=new Label("相同查询:");
		CheckBox cb1=new CheckBox("球类运动");
		CheckBox cb2=new CheckBox("文学阅读");
		CheckBox cb3=new CheckBox("文学创造");
		CheckBox cb4=new CheckBox("听音乐");
		CheckBox cb5=new CheckBox("看电影");
		CheckBox cb6=new CheckBox("绘画");
		CheckBox cb7=new CheckBox("舞蹈");
		CheckBox cb8=new CheckBox("冒险");
		CheckBox cb9=new CheckBox("收藏");
		CheckBox cb10=new CheckBox("网络游戏");
		CheckBox cb11=new CheckBox("喝茶");
		CheckBox cb12=new CheckBox("探索");
		VBox vb1=new VBox(10);
		VBox vb2=new VBox(10);
		VBox vb3=new VBox(10);
		VBox vb4=new VBox(10);
		vb1.getChildren().addAll(cb1,cb2,cb3);
		vb2.getChildren().addAll(cb4,cb5,cb6);
		vb3.getChildren().addAll(cb7,cb8,cb9);
		vb4.getChildren().addAll(cb10,cb11,cb12);
		HBox hb=new HBox(20);
		hb.getChildren().addAll(hobby,vb1,vb2,vb3,vb4);
		TextArea ta=new TextArea();
		ta.setPromptText("不可编辑");
		ta.setEditable(false);
		ta.setPrefHeight(200);
		ta.setWrapText(true);
		Button save=new Button("将查询结果导出");
		Label remark=new Label("备注:");
		Button exit=new Button("退出");
		exit.setPrefHeight(30);
		HBox hbo=new HBox(10);
		hbo.setAlignment(Pos.CENTER);
		hbo.getChildren().addAll(save,exit);
		exit.setOnAction(e->{
			Communication comm=new Communication();
			comm.start(new Stage());
			stage.close();
		});
		Text te=new Text("查询结果");
		Button button=new Button("查询");
		button.setTranslateX(50);
		button.setPrefWidth(450);
		button.setPrefHeight(30);
		button.setAlignment(Pos.CENTER);
		vb.getChildren().addAll(hbname,hbgroup,hbsex,hbage,hbcity,hb,button,te,ta,hbo);
		spane.getChildren().add(vb);
		stage.setTitle("添加好友到通讯录中");
		toggroup.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
	           @Override
	           public void changed(ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) {
	               if (toggroup.getSelectedToggle() != null) {
	                   RadioButton button = (RadioButton) toggroup.getSelectedToggle();
	                   GroupRadioButton=button.getText();
	               }
	           }
	       });
		tog.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
	           @Override
	           public void changed(ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) {
	               if (tog.getSelectedToggle() != null) {
	                   RadioButton button = (RadioButton) tog.getSelectedToggle();
	                   GroupSex=button.getText();
	               }
	           }
	       });
		cb1.setOnAction(e->{str+=cb1.getText()+"、";});
		cb2.setOnAction(e->{str+=cb2.getText()+"、";});
		cb3.setOnAction(e->{str+=cb3.getText()+"、";});
		cb4.setOnAction(e->{str+=cb4.getText()+"、";});
		cb5.setOnAction(e->{str+=cb5.getText()+"、";});
		cb6.setOnAction(e->{str+=cb6.getText()+"、";});
		cb7.setOnAction(e->{str+=cb7.getText()+"、";});
		cb8.setOnAction(e->{str+=cb8.getText()+"、";});
		cb9.setOnAction(e->{str+=cb9.getText()+"、";});
		cb10.setOnAction(e->{str+=cb10.getText()+"、";});
		cb11.setOnAction(e->{str+=cb11.getText()+"、";});
		cb12.setOnAction(e->{str+=cb12.getText()+"、";});
		Alert alert=new Alert(AlertType.INFORMATION);
		alert.setTitle("提示");
		alert.setHeaderText(null);
		clear.setOnAction(e->{
			tname.setText("");
			familyers.setSelected(false);
			colleague.setSelected(false);
			schoolmate.setSelected(false);
			teacher.setSelected(false);
			friend.setSelected(false);
			cb1.setSelected(false);
			cb2.setSelected(false);
			cb3.setSelected(false);
			cb4.setSelected(false);
			cb5.setSelected(false);
			cb6.setSelected(false);
			cb7.setSelected(false);
			cb8.setSelected(false);
			cb9.setSelected(false);
			cb10.setSelected(false);
			cb11.setSelected(false);
			cb12.setSelected(false);
			boy.setSelected(false);
			girl.setSelected(false);
			startage.setText("");
			endage.setText("");
			cbo.setValue("请选择城市");
		});
		button.setOnAction(e->{
			Connection conn=null;
			PreparedStatement ps=null;
			ResultSet rs=null;
			try {
				Class.forName(driver);
				conn=DriverManager.getConnection(url,user,password);
				if(tname.getText().length()>=1) {
					String select1="select Classification.sectionalization, Communication.* from Communication,Classification where Communication.telephone=classification.telephone and Communication.cName=? and users=?";
					ps=conn.prepareStatement(select1);
					ps.setString(1, tname.getText());
					ps.setString(2, User);
					rs=ps.executeQuery();
					boolean bool=true;
					while(rs.next()) {
						if(tname.getText().equals(rs.getString("cName"))) {
							String sname="姓名: "+rs.getString("cName");
							String sgroup="关系: "+rs.getString("sectionalization");
							String ssex="性别: "+rs.getString("sex");
							int iage=rs.getInt("age");
							String sage="年龄: "+String.valueOf(iage);
							String stel="电话: "+rs.getString("telephone");
							String smail="邮箱: "+rs.getString("mailbox");
							String scity="城市: "+rs.getString("city");
							String shobby="爱好: "+rs.getString("hobby");
							String sremark="备注: "+rs.getString("remark");
							String sevent="事迹: "+rs.getString("cevent");
							String st="";
							String subhobby=shobby.substring(0,shobby.length()-1);
							st+=sname+"\n"+sgroup+"\n"+ssex+"\n"+sage+"\n"+stel+"\n"+smail+"\n"+scity+
							"\n"+subhobby+"\n"+sremark+"\n"+sevent;
							ta.setText(st);
							bool=false;
						}
					}
					if(bool=false) {
						alert.setContentText("请选择您要查询的条件!");
						alert.showAndWait();
					}
				}
				if((GroupRadioButton!=null)&&(GroupSex!=null)&&(!startage.getText().equals(""))&&(!endage.getText().equals(""))
						&&(!cbo.getValue().equals("请选择城市"))&&(str.length()>0)) {
					String select="select Classification.cName,Classification.telephone from Communication,Classification where Communication.telephone=classification.telephone and Classification.sectionalization=?"
							+ "and sex=? and age between ? and ? and city=? and hobby=? and users=?";
					String selecthobby="select hobby from Communication where users=?";
					ps=conn.prepareStatement(selecthobby);
					ps.setString(1, User);
					rs=ps.executeQuery();
					int num=0;
					String sh;
					while(rs.next()) {
						String[] hob=new String[12];
						String[] strhob=new String[12];
						String shobby=rs.getString("hobby");
						String Str=str;
						int n=0,m=0;
						for(int i=0;shobby.length()>1;i++) {
							int index=shobby.indexOf("、");
							hob[i]=shobby.substring(0,index);
							n++;
							shobby=shobby.replace(shobby.substring(0,index+1), "");
						}
						for(int i=0;Str.length()>1;i++) {
							int index=Str.indexOf("、");
							strhob[i]=Str.substring(0,index);
							m++;
							Str=Str.replace(Str.substring(0,index+1), "");
						}
						if(m==n) {
							for(int i=0;i<m;i++) {
								for(int j=0;j<n;j++) {
									if(strhob[i].equals(hob[j])){
										num++;
									}
								}
							}
						}
						if(num==n) {
							sh=rs.getString("hobby");
							ps=conn.prepareStatement(select);
							ps.setString(1, GroupRadioButton);
							ps.setString(2, GroupSex);
							int start=Integer.parseInt(startage.getText());
							int end=Integer.parseInt(endage.getText());
							ps.setInt(3, start);
							ps.setInt(4, end);
							ps.setString(5, cbo.getValue());
							ps.setString(6, sh);
							ps.setString(7, User);
							rs=ps.executeQuery();
							String st=" 姓名		       电话\n",str1="";
							while(rs.next()) {
								String sname=rs.getString("cName")+"      ";
								String stel=rs.getString("telephone")+"\n";
								str1+=sname+stel;
							}
							ta.setText(st+str1);
						}
					}
				}
				if((GroupSex!=null)&&(!startage.getText().equals(""))&&(!endage.getText().equals(""))
						&&(!cbo.getValue().equals("请选择城市"))&&(str.length()>0)) {
					String select="select Classification.cName,Classification.telephone from Communication,Classification where Communication.telephone=classification.telephone"
							+ "and sex=? and age between ? and ? and city=? and hobby=? and users=?";
					String selecthobby="select hobby from Communication where users=?";
					ps=conn.prepareStatement(selecthobby);
					ps.setString(1, User);
					rs=ps.executeQuery();
					int num=0;
					String sh;
					while(rs.next()) {
						String[] hob=new String[12];
						String[] strhob=new String[12];
						String shobby=rs.getString("hobby");
						String Str=str;
						int n=0,m=0;
						for(int i=0;shobby.length()>1;i++) {
							int index=shobby.indexOf("、");
							hob[i]=shobby.substring(0,index);
							n++;
							shobby=shobby.replace(shobby.substring(0,index+1), "");
						}
						for(int i=0;Str.length()>1;i++) {
							int index=Str.indexOf("、");
							strhob[i]=Str.substring(0,index);
							m++;
							Str=Str.replace(Str.substring(0,index+1), "");
						}
						if(m==n) {
							for(int i=0;i<m;i++) {
								for(int j=0;j<n;j++) {
									if(strhob[i].equals(hob[j])){
										num++;
									}
								}
							}
						}
						if(num==n) {
							sh=rs.getString("hobby");
							ps=conn.prepareStatement(select);
							ps.setString(1, GroupSex);
							int start=Integer.parseInt(startage.getText());
							int end=Integer.parseInt(endage.getText());
							ps.setInt(2, start);
							ps.setInt(3, end);
							ps.setString(4, cbo.getValue());
							ps.setString(5, sh);
							ps.setString(6, User);
							rs=ps.executeQuery();
							String st=" 姓名		       电话\n",str1="";
							while(rs.next()) {
								String sname=rs.getString("cName")+"      ";
								String stel=rs.getString("telephone")+"\n";
								str1+=sname+stel;
							}
							ta.setText(st+str1);
						}
					}
				}
				if((!startage.getText().equals(""))&&(!endage.getText().equals(""))&&(!cbo.getValue().equals("请选择城市"))&&(str.length()>0)) {
					String select="select Classification.cName,Classification.telephone from Communication,Classification where Communication.telephone=classification.telephone"
							+ "and age between ? and ? and city=? and hobby=? and users=?";
					String selecthobby="select hobby from Communication where users=?";
					ps=conn.prepareStatement(selecthobby);
					ps.setString(1, User);
					rs=ps.executeQuery();
					int num=0;
					String sh;
					while(rs.next()) {
						String[] hob=new String[12];
						String[] strhob=new String[12];
						String shobby=rs.getString("hobby");
						String Str=str;
						int n=0,m=0;
						for(int i=0;shobby.length()>1;i++) {
							int index=shobby.indexOf("、");
							hob[i]=shobby.substring(0,index);
							n++;
							shobby=shobby.replace(shobby.substring(0,index+1), "");
						}
						for(int i=0;Str.length()>1;i++) {
							int index=Str.indexOf("、");
							strhob[i]=Str.substring(0,index);
							m++;
							Str=Str.replace(Str.substring(0,index+1), "");
						}
						if(m==n) {
							for(int i=0;i<m;i++) {
								for(int j=0;j<n;j++) {
									if(strhob[i].equals(hob[j])){
										num++;
									}
								}
							}
						}
						if(num==n) {
							sh=rs.getString("hobby");
							ps=conn.prepareStatement(select);
							int start=Integer.parseInt(startage.getText());
							int end=Integer.parseInt(endage.getText());
							ps.setInt(1, start);
							ps.setInt(2, end);
							ps.setString(3, cbo.getValue());
							ps.setString(4, sh);
							ps.setString(5, User);
							rs=ps.executeQuery();
							String st=" 姓名		       电话\n",str1="";
							while(rs.next()) {
								String sname=rs.getString("cName")+"      ";
								String stel=rs.getString("telephone")+"\n";
								str1+=sname+stel;
							}
							ta.setText(st+str1);
						}
					}
				}
				if((!cbo.getValue().equals("请选择城市"))&&(str.length()>0)) {
					String select="select Classification.cName,Classification.telephone from Communication,Classification where Communication.telephone=classification.telephone"
							+ "and city=? and hobby=? and users=?";
					String selecthobby="select hobby from Communication where users=?";
					ps=conn.prepareStatement(selecthobby);
					ps.setString(1, User);
					rs=ps.executeQuery();
					int num=0;
					String sh;
					while(rs.next()) {
						String[] hob=new String[12];
						String[] strhob=new String[12];
						String shobby=rs.getString("hobby");
						String Str=str;
						int n=0,m=0;
						for(int i=0;shobby.length()>1;i++) {
							int index=shobby.indexOf("、");
							hob[i]=shobby.substring(0,index);
							n++;
							shobby=shobby.replace(shobby.substring(0,index+1), "");
						}
						for(int i=0;Str.length()>1;i++) {
							int index=Str.indexOf("、");
							strhob[i]=Str.substring(0,index);
							m++;
							Str=Str.replace(Str.substring(0,index+1), "");
						}
						if(m==n) {
							for(int i=0;i<m;i++) {
								for(int j=0;j<n;j++) {
									if(strhob[i].equals(hob[j])){
										num++;
									}
								}
							}
						}
						if(num==n) {
							sh=rs.getString("hobby");
							ps=conn.prepareStatement(select);
							ps.setString(1, cbo.getValue());
							ps.setString(2, sh);
							ps.setString(3, User);
							rs=ps.executeQuery();
							String st=" 姓名		       电话\n",str1="";
							while(rs.next()) {
								String sname=rs.getString("cName")+"      ";
								String stel=rs.getString("telephone")+"\n";
								str1+=sname+stel;
							}
							ta.setText(st+str1);
						}
					}
				}
				if((!startage.getText().equals(""))&&(!endage.getText().equals(""))&&(str.length()>0)) {
					String select="select Classification.cName,Classification.telephone from Communication,Classification where Communication.telephone=classification.telephone and  age between ? and ? and hobby=? and users=?";
					String selecthobby="select hobby from Communication where users=?";
					ps=conn.prepareStatement(selecthobby);
					ps.setString(1, User);
					rs=ps.executeQuery();
					int num=0;
					String sh;
					while(rs.next()) {
						String[] hob=new String[12];
						String[] strhob=new String[12];
						String shobby=rs.getString("hobby");
						String Str=str;
						int n=0,m=0;
						for(int i=0;shobby.length()>1;i++) {
							int index=shobby.indexOf("、");
							hob[i]=shobby.substring(0,index);
							n++;
							shobby=shobby.replace(shobby.substring(0,index+1), "");
						}
						for(int i=0;Str.length()>1;i++) {
							int index=Str.indexOf("、");
							strhob[i]=Str.substring(0,index);
							m++;
							Str=Str.replace(Str.substring(0,index+1), "");
						}
						if(m==n) {
							for(int i=0;i<m;i++) {
								for(int j=0;j<n;j++) {
									if(strhob[i].equals(hob[j])){
										num++;
									}
								}
							}
						}
						if(num==n) {
							sh=rs.getString("hobby");
							ps=conn.prepareStatement(select);
							int start=Integer.parseInt(startage.getText());
							int end=Integer.parseInt(endage.getText());
							ps.setInt(1, start);
							ps.setInt(2, end);
							ps.setString(3, sh);
							ps.setString(4, User);
							rs=ps.executeQuery();
							String st=" 姓名		       电话\n",str1="";
							while(rs.next()) {
								String sname=rs.getString("cName")+"      ";
								String stel=rs.getString("telephone")+"\n";
								str1+=sname+stel;
							}
							ta.setText(st+str1);
						}
					}
				}
				if((GroupSex!=null)&&(str.length()>0)) {
					String select="select Classification.cName,Classification.telephone from Communication,Classification where Communication.telephone=classification.telephone and sex=? and hobby=? and users=?";
					String selecthobby="select hobby from Communication where users=?";
					ps=conn.prepareStatement(selecthobby);
					ps.setString(1, User);
					rs=ps.executeQuery();
					int num=0;
					String sh;
					while(rs.next()) {
						String[] hob=new String[12];
						String[] strhob=new String[12];
						String shobby=rs.getString("hobby");
						String Str=str;
						int n=0,m=0;
						for(int i=0;shobby.length()>1;i++) {
							int index=shobby.indexOf("、");
							hob[i]=shobby.substring(0,index);
							n++;
							shobby=shobby.replace(shobby.substring(0,index+1), "");
						}
						for(int i=0;Str.length()>1;i++) {
							int index=Str.indexOf("、");
							strhob[i]=Str.substring(0,index);
							m++;
							Str=Str.replace(Str.substring(0,index+1), "");
						}
						if(m==n) {
							for(int i=0;i<m;i++) {
								for(int j=0;j<n;j++) {
									if(strhob[i].equals(hob[j])){
										num++;
									}
								}
							}
						}
						if(num==n) {
							sh=rs.getString("hobby");
							ps=conn.prepareStatement(select);
							ps.setString(1, GroupSex);
							ps.setString(2, sh);
							ps.setString(3, User);
							rs=ps.executeQuery();
							String st=" 姓名		       电话\n",str1="";
							while(rs.next()) {
								String sname=rs.getString("cName")+"      ";
								String stel=rs.getString("telephone")+"\n";
								str1+=sname+stel;
							}
							ta.setText(st+str1);
						}
					}
				}
				if((GroupRadioButton!=null)&&(GroupSex!=null)&&(!startage.getText().equals(""))&&(!endage.getText().equals(""))
						&&(!cbo.getValue().equals("请选择城市"))&&(str.length()>0)) {
					String select="select Classification.cName,Classification.telephone from Communication,Classification where Communication.telephone=classification.telephone and Classification.sectionalization=? and hobby=? and users=?";
					String selecthobby="select hobby from Communication where users=?";
					ps=conn.prepareStatement(selecthobby);
					ps.setString(1, User);
					rs=ps.executeQuery();
					int num=0;
					String sh;
					while(rs.next()) {
						String[] hob=new String[12];
						String[] strhob=new String[12];
						String shobby=rs.getString("hobby");
						String Str=str;
						int n=0,m=0;
						for(int i=0;shobby.length()>1;i++) {
							int index=shobby.indexOf("、");
							hob[i]=shobby.substring(0,index);
							n++;
							shobby=shobby.replace(shobby.substring(0,index+1), "");
						}
						for(int i=0;Str.length()>1;i++) {
							int index=Str.indexOf("、");
							strhob[i]=Str.substring(0,index);
							m++;
							Str=Str.replace(Str.substring(0,index+1), "");
						}
						if(m==n) {
							for(int i=0;i<m;i++) {
								for(int j=0;j<n;j++) {
									if(strhob[i].equals(hob[j])){
										num++;
									}
								}
							}
						}
						if(num==n) {
							sh=rs.getString("hobby");
							ps=conn.prepareStatement(select);
							ps.setString(1, GroupRadioButton);
							ps.setString(2, sh);
							ps.setString(3, User);
							rs=ps.executeQuery();
							String st=" 姓名		       电话\n",str1="";
							while(rs.next()) {
								String sname=rs.getString("cName")+"      ";
								String stel=rs.getString("telephone")+"\n";
								str1+=sname+stel;
							}
							ta.setText(st+str1);
						}
					}
				}
				if((GroupRadioButton!=null)&&(GroupSex!=null)&&(!startage.getText().equals(""))&&(!endage.getText().equals(""))
						&&(!cbo.getValue().equals("请选择城市"))) {
					String select="select Classification.cName,Classification.telephone from Communication,Classification where Communication.telephone=classification.telephone and Classification.sectionalization=?"
							+ "and sex=? and age between ? and ? and city=? and users=?";
					ps=conn.prepareStatement(select);
					ps.setString(1, GroupRadioButton);
					ps.setString(2, GroupSex);
					int start=Integer.parseInt(startage.getText());
					int end=Integer.parseInt(endage.getText());
					ps.setInt(3, start);
					ps.setInt(4, end);
					ps.setString(5, cbo.getValue());
					ps.setString(6, User);
					rs=ps.executeQuery();
					String st=" 姓名		       电话\n",str1="";
					while(rs.next()) {
						String sname=rs.getString("cName")+"      ";
						String stel=rs.getString("telephone")+"\n";
						str1+=sname+stel;
					}
					ta.setText(st+str1);
				}
				if((GroupSex!=null)&&(!startage.getText().equals(""))&&(!endage.getText().equals(""))
						&&(!cbo.getValue().equals("请选择城市"))) {
					String select="select Classification.cName,Classification.telephone from Communication,Classification where Communication.telephone=classification.telephone"
							+ "and sex=? and age between ? and ? and city=? and users=?";
					ps=conn.prepareStatement(select);
					ps.setString(1, GroupSex);
					int start=Integer.parseInt(startage.getText());
					int end=Integer.parseInt(endage.getText());
					ps.setInt(2, start);
					ps.setInt(3, end);
					ps.setString(4, cbo.getValue());
					ps.setString(5, User);
					rs=ps.executeQuery();
					String st=" 姓名		       电话\n",str1="";
					while(rs.next()) {
						String sname=rs.getString("cName")+"      ";
						String stel=rs.getString("telephone")+"\n";
						str1+=sname+stel;
					}
					ta.setText(st+str1);
				}
				if((!startage.getText().equals(""))&&(!endage.getText().equals(""))
						&&(!cbo.getValue().equals("请选择城市"))) {
					String select="select Classification.cName,Classification.telephone from Communication,Classification where Communication.telephone=classification.telephone"
							+ "and age between ? and ? and city=? and users=?";
					ps=conn.prepareStatement(select);
					int start=Integer.parseInt(startage.getText());
					int end=Integer.parseInt(endage.getText());
					ps.setInt(1, start);
					ps.setInt(2, end);
					ps.setString(3, cbo.getValue());
					ps.setString(4, User);
					rs=ps.executeQuery();
					String st=" 姓名		       电话\n",str1="";
					while(rs.next()) {
						String sname=rs.getString("cName")+"      ";
						String stel=rs.getString("telephone")+"\n";
						str1+=sname+stel;
					}
					ta.setText(st+str1);
				}
				if((GroupRadioButton!=null)&&(GroupSex!=null)&&(!startage.getText().equals(""))&&(!endage.getText().equals(""))) {
					String select="select Classification.cName,Classification.telephone from Communication,Classification where Communication.telephone=classification.telephone and Classification.sectionalization=?"
							+ "and sex=? and age between ? and ?  and users=?";
					ps=conn.prepareStatement(select);
					ps.setString(1, GroupRadioButton);
					ps.setString(2, GroupSex);
					int start=Integer.parseInt(startage.getText());
					int end=Integer.parseInt(endage.getText());
					ps.setInt(3, start);
					ps.setInt(4, end);
					ps.setString(6, User);
					rs=ps.executeQuery();
					String st=" 姓名		       电话\n",str1="";
					while(rs.next()) {
						String sname=rs.getString("cName")+"      ";
						String stel=rs.getString("telephone")+"\n";
						str1+=sname+stel;
					}
					ta.setText(st+str1);
				}
				if((GroupSex!=null)&&(!startage.getText().equals(""))&&(!endage.getText().equals(""))) {
					String select="select Classification.cName,Classification.telephone from Communication,Classification where Communication.telephone=classification.telephone"
							+ "and sex=? and age between ? and ?  and users=?";
					ps=conn.prepareStatement(select);
					ps.setString(1, GroupSex);
					int start=Integer.parseInt(startage.getText());
					int end=Integer.parseInt(endage.getText());
					ps.setInt(2, start);
					ps.setInt(3, end);
					ps.setString(6, User);
					rs=ps.executeQuery();
					String st=" 姓名		       电话\n",str1="";
					while(rs.next()) {
						String sname=rs.getString("cName")+"      ";
						String stel=rs.getString("telephone")+"\n";
						str1+=sname+stel;
					}
					ta.setText(st+str1);
				}
				if((GroupRadioButton!=null)&&(GroupSex!=null)) {
					String select="select Classification.cName,Classification.telephone from Communication,Classification where Communication.telephone=classification.telephone and Classification.sectionalization=?"
							+ "and sex=? and users=?";
					ps=conn.prepareStatement(select);
					ps.setString(1, GroupRadioButton);
					ps.setString(2, GroupSex);
					ps.setString(3, User);
					rs=ps.executeQuery();
					String st=" 姓名		       电话\n",str1="";
					while(rs.next()) {
						String sname=rs.getString("cName")+"      ";
						String stel=rs.getString("telephone")+"\n";
						str1+=sname+stel;
					}
					ta.setText(st+str1);
				}
				if(GroupRadioButton!=null) {
					String select="select Classification.cName,Classification.telephone from Communication,Classification where Communication.telephone=classification.telephone and Classification.sectionalization=? and users=?";
					ps=conn.prepareStatement(select);
					ps.setString(1, GroupRadioButton);
					ps.setString(2, User);
					rs=ps.executeQuery();
					String st=" 姓名		       电话\n",str1="";
					while(rs.next()) {
						String sname=rs.getString("cName")+"      ";
						String stel=rs.getString("telephone")+"\n";
						str1+=sname+stel;
					}
					ta.setText(st+str1);
				}
				if(GroupSex!=null) {
					String select="select Classification.cName,Classification.telephone from Communication,Classification where Communication.telephone=classification.telephone and Communication.sex=? and users=?";
					ps=conn.prepareStatement(select);
					ps.setString(1, GroupSex);
					ps.setString(2, User);
					rs=ps.executeQuery();
					String st=" 姓名		       电话\n",str1="";
					while(rs.next()) {
						String sname=rs.getString("cName")+"      ";
						String stel=rs.getString("telephone")+"\n";
						str1+=sname+stel;
					}
					ta.setText(st+str1);
				}
				if(!startage.getText().equals("")&&!endage.getText().equals("")) {
					String select="select Classification.cName,Classification.telephone from Communication,Classification where Communication.telephone=classification.telephone and Communication.age between ? and ? and users=?";
					ps=conn.prepareStatement(select);
					int start=Integer.parseInt(startage.getText());
					int end=Integer.parseInt(endage.getText());
					ps.setInt(1, start);
					ps.setInt(2, end);
					ps.setString(3, User);
					rs=ps.executeQuery();
					String st=" 姓名		       电话\n",str1="";
					while(rs.next()) {
						String sname=rs.getString("cName")+"      ";
						String stel=rs.getString("telephone")+"\n";
						str1+=sname+stel;
						ta.setText(str1);
					}
				}
				if(!cbo.getValue().equals("请选择城市")) {
					String select="select Classification.cName,Classification.telephone from Communication,Classification where Communication.telephone=classification.telephone and Communication.city=? and users=?";
					ps=conn.prepareStatement(select);
					ps.setString(1, cbo.getValue());
					ps.setString(2, User);
					rs=ps.executeQuery();
					String st=" 姓名		       电话\n",str1="";
					while(rs.next()) {
						String sname=rs.getString("cName")+"      ";
						String stel=rs.getString("telephone")+"\n";
						str1+=sname+stel;
					}
					ta.setText(st+str1);
				}
				if(str.length()>0) {
					String select="select Classification.cName,Classification.telephone from Communication,Classification where Communication.telephone=classification.telephone and hobby=? and users=?";
					String selecthobby="select hobby from Communication where users=?";
					ps=conn.prepareStatement(selecthobby);
					ps.setString(1, User);
					rs=ps.executeQuery();
					int num=0;
					String sh;
					while(rs.next()) {
						String[] hob=new String[12];
						String[] strhob=new String[12];
						String shobby=rs.getString("hobby");
						String Str=str;
						int n=0,m=0;
						for(int i=0;shobby.length()>1;i++) {
							int index=shobby.indexOf("、");
							hob[i]=shobby.substring(0,index);
							n++;
							shobby=shobby.replace(shobby.substring(0,index+1), "");
						}
						for(int i=0;Str.length()>1;i++) {
							int index=Str.indexOf("、");
							strhob[i]=Str.substring(0,index);
							m++;
							Str=Str.replace(Str.substring(0,index+1), "");
						}
						if(m==n) {
							for(int i=0;i<m;i++) {
								for(int j=0;j<n;j++) {
									if(strhob[i].equals(hob[j])){
										num++;
									}
								}
							}
						}
						if(num==n) {
							sh=rs.getString("hobby");
							ps=conn.prepareStatement(select);
							ps.setString(1, sh);
							ps.setString(2, User);
							rs=ps.executeQuery();
							String st=" 姓名		       电话\n",str1="";
							while(rs.next()) {
								String sname=rs.getString("cName")+"      ";
								String stel=rs.getString("telephone")+"\n";
								str1+=sname+stel;
							}
							ta.setText(st+str1);
						}
					}
				}
				
			}catch(Exception ex) {
				ex.printStackTrace();
			}finally {
				try {
					if(rs!=null) {
						rs.close();
					}if(ps!=null) {
						ps.close();
					}if(conn!=null) {
						conn.close();
					}
				}catch(Exception ex) {
					ex.printStackTrace();
				}
			}
			
		});
		save.setOnAction(e->{
			FileChooser fc=new FileChooser();
			fc.setTitle("文件保存对话框");
			fc.setInitialDirectory(new File("C:\\Java文件流"));
			FileChooser.ExtensionFilter filter=new FileChooser.ExtensionFilter(".txt", "*.txt");
			fc.getExtensionFilters().add(filter);//设置文件过滤器
			File file=fc.showSaveDialog(stage);
			if(file!=null) {
				try {
					FileOutputStream f=new FileOutputStream(file);
					BufferedOutputStream out=new BufferedOutputStream(f);
					if(ta.getText().equals("")) {
						alert.setContentText("导出内容不能为空");
						alert.showAndWait();
					}else {
						byte[]b=(ta.getText()).getBytes();
						out.write(b,0,b.length);
						out.close();
					}
				}catch(IOException ioe) {};
			}
		});
		Scene scene=new Scene(spane,600,650);
		stage.setScene(scene);
		stage.show();	
	}
}
class Output extends Application
{
	public static String User;
	private static String driver="com.mysql.cj.jdbc.Driver";
	private static String url="jdbc:mysql://localhost:3306/test?serverTimezone=UTC";
	private static String user="root";
	private static String password="123456";
	@Override
	public void start(Stage stage)
	{
		Text t=new Text("请输入您要导出好友的姓名");
		t.setFont(new Font("黑体",18));
		Label lab=new Label("姓名:");
		TextField text=new TextField();
		Button button=new Button("查询");
		StackPane spane=new StackPane();
		spane.setPadding(new Insets(10));
		HBox hb=new HBox(20);
		hb.setTranslateY(40);
		hb.setAlignment(Pos.CENTER);
		hb.getChildren().addAll(lab,text,button);
		BorderPane bpane=new BorderPane();
		Alert alert=new Alert(AlertType.INFORMATION);
		alert.setTitle("错误");
		alert.setHeaderText(null);
		Button output=new Button("导出单个好友信息");
		Button outputall=new Button("导出全部好友信息");
		Button cannel=new Button("退出");
		cannel.setOnAction(e->{
			Communication comm=new Communication();
			comm.start(new Stage());
			stage.close();
		});
		HBox oc=new HBox(20);
		oc.setAlignment(Pos.CENTER);
		TextArea ta=new TextArea();
		ta.setWrapText(true);
		ta.setPromptText("不可编辑");
		ta.setEditable(false);
		ta.setPrefHeight(200);
		ta.setTranslateY(100);
		t.setTranslateY(-80);
		hb.setTranslateY(-40);
		spane.getChildren().addAll(t,hb,ta);
		bpane.setPadding(new Insets(20));
		bpane.setTop(spane);
		bpane.setBottom(oc);
		oc.getChildren().addAll(output,outputall,cannel);
		button.setOnAction(e->{
			String selectsql="select cName from Communication where users=?;";
			Connection conn=null;
			PreparedStatement ps=null;
			ResultSet rs=null;
			try {
				Class.forName(driver);
				conn=DriverManager.getConnection(url,user,password);
				ps=conn.prepareStatement(selectsql);
				ps.setString(1, User);
				rs=ps.executeQuery();
				while(rs.next()) {
					if(text.getText().equals(rs.getString("cName"))) {
						String name=text.getText();
						String select="select Communication.*,Classification.sectionalization from Communication,Classification"
								+ " where Communication.telephone=classification.telephone and Communication.cName=?;";
						try {
							ps=conn.prepareStatement(select);
							ps.setString(1, name);
							rs=ps.executeQuery();
							while(rs.next()) {
								String sname="姓名: "+rs.getString("cName");
								String sgroup="关系: "+rs.getString("sectionalization");
								String ssex="性别: "+rs.getString("sex");
								int iage=rs.getInt("age");
								String sage="年龄: "+String.valueOf(iage);
								String stel="电话: "+rs.getString("telephone");
								String smail="邮箱: "+rs.getString("mailbox");
								String scity="城市: "+rs.getString("city");
								String shobby="爱好: "+rs.getString("hobby");
								String sremark="备注: "+rs.getString("remark");
								String sevent="事迹: "+rs.getString("cevent");
								String subhobby=shobby.substring(0,shobby.length()-1);
								String str=sname+"\n"+sgroup+"\n"+ssex+"\n"+sage+"\n"+stel+"\n"+smail+"\n"+scity+
										"\n"+subhobby+"\n"+sremark+"\n"+sevent;
								ta.setText(str);
							}
							
						}catch(Exception ex) {
							ex.printStackTrace();
						}
					}else {
						alert.setContentText("查无此人,请重新输入!");
						alert.showAndWait();
					}
				}
			}catch(Exception ex) {
				ex.printStackTrace();
			}
		});
		output.setOnAction(e->{
			if(text.getText().equals("")) {
				alert.setContentText("请先调出您要导出的好友");
				alert.showAndWait();
			}else {
				FileChooser fc=new FileChooser();
				fc.setTitle("文件保存对话框");
				fc.setInitialDirectory(new File("C:\\Java文件流"));
				FileChooser.ExtensionFilter filter=new FileChooser.ExtensionFilter(".txt", "*.txt");
				fc.getExtensionFilters().add(filter);//设置文件过滤器
				File file=fc.showSaveDialog(stage);
				if(file!=null) {
					try {
						FileOutputStream f=new FileOutputStream(file);
						BufferedOutputStream out=new BufferedOutputStream(f);
						byte[]b=(ta.getText()).getBytes();
						out.write(b,0,b.length);
						out.close();
					}catch(IOException ioe) {};
				}
			}
		});
		outputall.setOnAction(e->{
			Connection conn=null;
			PreparedStatement ps=null;
			ResultSet rs=null;
			String select="select Communication.*,Classification.sectionalization from Communication,Classification"
					+ " where Communication.telephone=classification.telephone and Communication.users=?;";
			try {
				Class.forName(driver);
				conn=DriverManager.getConnection(url,user,password);
				ps=conn.prepareStatement(select);
				ps.setString(1, User);
				rs=ps.executeQuery();
				String str="";
				while(rs.next()) {
					String sname="姓名: "+rs.getString("cName");
					String sgroup="关系: "+rs.getString("sectionalization");
					String ssex="性别: "+rs.getString("sex");
					int iage=rs.getInt("age");
					String sage="年龄: "+String.valueOf(iage);
					String stel="电话: "+rs.getString("telephone");
					String smail="邮箱: "+rs.getString("mailbox");
					String scity="城市: "+rs.getString("city");
					String shobby="爱好: "+rs.getString("hobby");
					String sremark="备注: "+rs.getString("remark");
					String sevent="事迹: "+rs.getString("cevent");
					String subhobby=shobby.substring(0,shobby.length()-1);	
					str+=sname+"\n"+sgroup+"\n"+ssex+"\n"+sage+"\n"+stel+"\n"+smail+"\n"+scity+
							"\n"+subhobby+"\n"+sremark+"\n"+sevent+"\n"+"\n";
				}
				FileChooser fc=new FileChooser();
				fc.setTitle("文件保存对话框");
				fc.setInitialDirectory(new File("C:\\Java文件流"));
				FileChooser.ExtensionFilter filter=new FileChooser.ExtensionFilter(".txt", "*.txt");
				fc.getExtensionFilters().add(filter);//设置文件过滤器
				File file=fc.showSaveDialog(stage);
				if(file!=null) {
					try {
						FileOutputStream f=new FileOutputStream(file);
						BufferedOutputStream out=new BufferedOutputStream(f);
						byte[]b=(str).getBytes();
						out.write(b,0,b.length);
						out.close();
					}catch(IOException ioe) {
						ioe.printStackTrace();
					}
				}
			}catch(Exception ex) {
				ex.printStackTrace();
			}finally {
				try {
					if(rs!=null)
						rs.close();
					if(ps!=null)
						ps.close();
					if(conn!=null)
						conn.close();
				}catch(Exception ex) {
					ex.toString();
				}
			}
		});
		Scene scene=new Scene(bpane,500,400);
		stage.setTitle("导出通讯录好友信息");
		stage.setScene(scene);
		stage.show();
	}
}
class Enroll extends Application
{
	private static String driver="com.mysql.cj.jdbc.Driver";
	private static String url="jdbc:mysql://localhost:3306/test?serverTimezone=UTC";
	private static String user="root";
	private static String password="123456";
	private Connection conn=null;
	private PreparedStatement ps=null;
	@Override
	public void start(Stage primaryStage)
	{
		final TextField tf=new TextField();
		final PasswordField pf=new PasswordField();
		final TextField tel=new TextField();
		final Label username=new Label("用户名:");
		final Label telephone=new Label("号  码:");
		final Label userpassword=new Label("密  码:");
		final Button enroll=new Button("立即注册");
		Alert alert=new Alert(AlertType.INFORMATION);
		alert.setTitle("错误");
		alert.setHeaderText(null);
		enroll.setPrefWidth(200);
		StackPane spane=new StackPane();
		Text text=new Text("欢迎注册");
		text.setFont(new Font("黑体",20));
		text.setTranslateY(80);
		spane.getChildren().add(text);
		tf.setPromptText("请输入用户名");
		pf.setPromptText("请输入密码");
		tel.setPromptText("手机号码");
		GridPane gpane=new GridPane();
		gpane.setHgap(10);
		gpane.setVgap(15);
		gpane.setAlignment(Pos.CENTER);
		gpane.add(username, 0, 0);
		gpane.add(tf, 1, 0);
		gpane.add(userpassword, 0, 1);
		gpane.add(pf, 1, 1);
		gpane.add(telephone, 0, 2);
		gpane.add(tel, 1, 2);
		gpane.add(enroll, 1, 3);
		BorderPane bpane=new BorderPane();
		bpane.setTop(spane);
		bpane.setCenter(gpane);
		enroll.setOnAction(e->{
			if(tel.getText().length()!=11) {
				alert.setContentText("电话输入错误,请重新输入");
				alert.showAndWait();
				tel.setText("");
			}else if(pf.getText().length()<6) {
				alert.setContentText("密码长度不能少于6位");
				alert.showAndWait();
				pf.setText("");
			}else {
				String select="select users from user";
				try {
					Class.forName(driver);
					Connection co=DriverManager.getConnection(url,user,password);
					Statement stmt=co.createStatement();
					ResultSet rs=stmt.executeQuery(select);
					while(rs.next()) {
						if(tf.getText().equals(rs.getString("users"))) {
							alert.setContentText("该用户已经存在,请重新输入");
							alert.showAndWait();
							break;
						}else {
							String insertsql="insert into user values(?,?,?)";
							try {
								Class.forName(driver);
								conn=DriverManager.getConnection(url,user,password);
								ps=conn.prepareStatement(insertsql);
								ps.setString(1, tf.getText());
								ps.setString(2, pf.getText());
								ps.setString(3, tel.getText());
								ps.executeUpdate();
							}catch(Exception ex) {
								ex.printStackTrace();
							}finally {
								try {
									if(ps!=null)
										ps.close();
									if(conn!=null)
										conn.close();
								}catch(Exception ex) {
									ex.printStackTrace();
								}
							}
							alert.setContentText("账号已注册成功!");
							alert.showAndWait();
							primaryStage.hide();
							Java java=new Java();
							java.start(new Stage());
						}
					}
				}catch(Exception ex) {
					ex.printStackTrace();
				}
			}
		});
		Scene scene=new Scene(bpane,500,400);
		primaryStage.setTitle("注册");
		primaryStage.setScene(scene);
		primaryStage.show();
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值