热烈庆贺清明小长假的到来
代码(java):
package softwareTest;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class Lueluelue extends Application{
public static void main(String[] args) {
Application.launch(args);
}
public void start(final Stage stage) throws Exception {
stage.setTitle("testing");
final AnchorPane root = new AnchorPane();
final TextField input0 = new TextField();
final TextField input1 = new TextField();
final TextField input2 = new TextField();
final Button button = new Button("click");
final Text text1 = new Text("请正确输入");
final Text text2 = new Text("正确");
button.setOnAction(new EventHandler<ActionEvent>(){
public void handle(ActionEvent arg0){
for(int j = 0 ; j <= 2 ; j ++){
String string0 = input0.getText();
char [] str0 = string0.toCharArray();
if(j == 0){
string0 = input0.getText();
str0 = string0.toCharArray();
}
else if(j == 1){
string0 = input1.getText();
str0 = string0.toCharArray();
}
else{
string0 = input2.getText();
str0 = string0.toCharArray();
}
if(str0.length>0 && str0.length<7){
int i = 0;
for(i = 0 ; i < str0.length ; i ++){
if((str0[i]>='0' && str0[i]<='9') ||
(str0[i]>='a' && str0[i]<='z') ||
(str0[i]>='A' && str0[i]<='Z')){
continue;
}
else{
AnchorPane.setTopAnchor(text1,(double) 140);
root.getChildren().addAll(text1);
stage.show();
break;
}
}
if(i == str0.length){
if(j == 2){
AnchorPane.setTopAnchor(text2,(double) 140);
root.getChildren().addAll(text2);
stage.show();
break;
}
else
break;
}
}
else{
AnchorPane.setTopAnchor(text1,(double) 140);
root.getChildren().addAll(text1);
stage.show();
break;
}
}
}
});
AnchorPane.setTopAnchor(input0,(double) 40);
AnchorPane.setTopAnchor(input1,(double) 80);
AnchorPane.setTopAnchor(input2,(double) 120);
AnchorPane.setTopAnchor(button,(double) 170);
root.getChildren().addAll(input0,input1,input2,button);
stage.setScene(new Scene(root,200,200));
stage.show();
}
}
测试截图:
么么哒!