标签:handle void zab exit windows resizable box black art
FoundFace 主要实现密码找回功能及界面。
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
public class FoundFace extends Application{
public void start(Stage primaryStage) {
SqlLink sql=new SqlLink();
Image over=new Image("over.jpg");
ImageView headImage=new ImageView(over);
Button btSubmit=new Button("提 交");
btSubmit.setPadding(new Insets(5,30,5,30));
btSubmit.setCursor(Cursor.HAND);
Button btExit=new Button("取 消");
btExit.setPadding(new Insets(5,30,5,30));
btExit.setCursor(Cursor.HAND);
Button btCheck=new Button("显 示 密 保 问 题");
btCheck.setPadding(new Insets(5,27,5,27));
btCheck.setCursor(Cursor.HAND);
Label lbUsername=new Label("帐号:");
Label lbUserCheck=new Label();
Label lbQuestion1=new Label("密保问题:");
Label lbQuestion2=new Label();
Label lbAnswer=new Label("答案:");
Label lbPassword1=new Label("新的密码:");
Label lbPassword2=new Label("确认密码:");
TextField tfUsername=new TextField();
tfUsername.setPrefColumnCount(12);
TextField tfAnswer=new TextField();
tfAnswer.setPrefColumnCount(12);
PasswordField pfPassword1=new PasswordField();
pfPassword1.setPrefColumnCount(12);
PasswordField pfPassword2=new PasswordField();
pfPassword2.setPrefColumnCount(12);
GridPane pane1=new GridPane();
pane1.setAlignment(Pos.CENTER);
pane1.setPadding(new Insets(15,0,0,0));
pane1.setHgap(10);
pane1.setVgap(10);
pane1.add(lbUsername,0,0);
pane1.add(tfUsername,1,0);
pane1.add(lbQuestion1,0,1);
pane1.add(btCheck,1,1);
pane1.add(lbAnswer,0,2);
pane1.add(tfAnswer,1,2);
pane1.add(lbPassword1,0,3);
pane1.add(pfPassword1,1,3);
pane1.add(lbPassword2,0,4);
pane1.add(pfPassword2,1,4);
GridPane pane2=new GridPane();
pane2.setAlignment(Pos.CENTER);
pane2.setPadding(new Insets(-15,0,10,0));
pane2.setHgap(20);
pane2.setVgap(10);
pane2.add(btSubmit,0,3);
pane2.add(btExit,1,3);
VBox vBox=new VBox();
vBox.setAlignment(Pos.CENTER);
vBox.setPadding(new Insets(0,0,0,0));
vBox.getChildren().addAll(headImage,pane1,pane2);
btCheck.setOnMouseClicked(new EventHandler<MouseEvent>(){
public void handle(MouseEvent arg0) {
if(sql.checkUser(tfUsername.getText())){
lbQuestion2.setText(sql.getQuestion(tfUsername.getText()));
lbQuestion2.setPadding(new Insets(5,5,5,5));
lbUserCheck.setText(tfUsername.getText());
lbQuestion2.setTextFill(Color.BLACK);
lbUserCheck.setPadding(new Insets(5,25,5,5));
HBox hBox=new HBox();
Button button=new Button("重新输入");
button.setCursor(Cursor.HAND);
button.setOnMouseClicked(new EventHandler<MouseEvent>(){
public void handle(MouseEvent arg0) {
pane1.getChildren().remove(hBox);
pane1.add(tfUsername, 1, 0);
pane1.add(btCheck, 1, 1);
}
});
button.setPadding(new Insets(5,10,5,10));
hBox.getChildren().addAll(lbUserCheck,button);
pane1.getChildren().remove(btCheck);
pane1.getChildren().remove(tfUsername);
pane1.add(hBox, 1, 0);
pane1.add(lbQuestion2, 1, 1);
}else{
lbQuestion2.setText("未找到此帐号!");
lbQuestion2.setTextFill(Color.RED);
lbQuestion2.setPadding(new Insets(5,5,5,5));
pane1.getChildren().remove(btCheck);
HBox hBox=new HBox();
Button button=new Button("重新输入");
button.setCursor(Cursor.HAND);
button.setOnMouseClicked(new EventHandler<MouseEvent>(){
public void handle(MouseEvent arg0) {
pane1.getChildren().remove(hBox);
pane1.add(btCheck, 1, 1);
}
});
button.setPadding(new Insets(5,10,5,10));
hBox.getChildren().addAll(lbQuestion2,button);
pane1.add(hBox, 1, 1);
}
}
});
btSubmit.setOnMouseClicked(new EventHandler<MouseEvent>(){
public void handle(MouseEvent e){
Label lbMessage=new Label();
GridPane pane =new GridPane();
Stage stage=new Stage();
if(sql.changeUser(tfUsername.getText(), pfPassword1.getText())){
lbMessage.setText(" 修改密码成功!");
Button button=new Button("确定");
button.setPadding(new Insets(5,30,5,30));
button.setCursor(Cursor.HAND);
button.setOnMouseClicked(new EventHandler<MouseEvent>(){
public void handle(MouseEvent e){
new LoginFace().start(new Stage());
stage.close();
primaryStage.close();
}
});
pane.add(button,0,1);
pane.setVgap(20);
}else{
lbMessage.setText("密保答案错误!请重新输入!");
}
pane.add(lbMessage,0,0);
pane.setAlignment(Pos.CENTER);
stage.setTitle("修改提示");
stage.setScene(new Scene(pane));
stage.setHeight(120);
stage.setWidth(250);
stage.getIcons().add(new Image("char_bg.png"));
stage.show();
}
});
btExit.setOnMouseClicked(new EventHandler<MouseEvent>(){
public void handle(MouseEvent e){
new LoginFace().start(new Stage());
primaryStage.close();
}
});
Scene scene=new Scene(vBox,400,335);
primaryStage.setTitle("找回狙击坦克的士兵!");
primaryStage.setWidth(400);
primaryStage.setHeight(335);
primaryStage.setResizable(false);
primaryStage.getIcons().add(new Image("char_bg.png"));
primaryStage.setScene(scene);
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>(){
public void handle(WindowEvent e){
new LoginFace().start(new Stage());
primaryStage.close();
}
});
primaryStage.show();
}
}
标签:handle void zab exit windows resizable box black art
原文地址:http://www.cnblogs.com/hwb04160011/p/6625119.html