package threebox;
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.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class lab4 extends Application{
public static void main(String[]args)
{
lab4.launch(args);
}
public void start(Stage primaryStage)
{
primaryStage.setTitle("Transition Lab");
AnchorPane anchorpane = new AnchorPane();
Button btn = new Button( );
btn.setText("OK");
AnchorPane.setTopAnchor(btn, 350.0);
AnchorPane.setLeftAnchor(btn, 250.0);
Text text = new Text("user name:");
text.setFont(new Font(24));
text.setFill(Color.BLACK);
AnchorPane.setTopAnchor(text, 50.0);
AnchorPane.setLeftAnchor(text, 50.0);
final TextField textf = new TextField();
AnchorPane.setTopAnchor(textf, 50.0);
AnchorPane.setLeftAnchor(textf, 300.0);
Text text2 = new Text("password:");
text2.setFill(Color.BLACK);
text2.setFont(new Font(24));
AnchorPane.setTopAnchor(text2, 150.0);
AnchorPane.setLeftAnchor(text2, 50.0);
final TextField textf2 = new TextField();
AnchorPane.setTopAnchor(textf2, 150.0);
AnchorPane.setLeftAnchor(textf2, 300.0);
Text text3 = new Text("verification code:");
text3.setFill(Color.BLACK);
text3.setFont(new Font(24));
AnchorPane.setTopAnchor(text3, 250.0);
AnchorPane.setLeftAnchor(text3, 50.0);
text3.setX(50);
text3.setY(250);
final TextField textf3 = new TextField();
AnchorPane.setTopAnchor(textf3, 250.0);
AnchorPane.setLeftAnchor(textf3, 300.0);
btn.setOnAction( new EventHandler<ActionEvent>( ) {
public void handle(ActionEvent actEvt) {
String sql1 = textf.getText();
String sql2=new String();
sql2=textf2.getText();
String sql3=new String();
sql3=textf3.getText();
int length1=sql1.length();
int length2=sql2.length();
int length3=sql3.length();
if((length1<7)&&(length1>0)&&(length2<7)&&(length2>0)&&(length3<7)&&(length3>0)){
System.out.println("the length is not enough");
}
for(int i= 0;i<=length1;i++){
if((sql1.charAt(i)<49)||((sql1.charAt(i)>54)&&(sql1.charAt(i)<65))||((sql1.charAt(i)>90)&&(sql1.charAt(i)<97))||(sql1.charAt(i)>122))
{
System.out.println("not the real character");
}
}
for(int i= 0;i<=length2;i++){
if((sql2.charAt(i)<49)||((sql2.charAt(i)>54)&&(sql2.charAt(i)<65))||((sql2.charAt(i)>90)&&(sql2.charAt(i)<97))||(sql2.charAt(i)>122))
{
System.out.println("not the real character");
}
}
for(int i= 0;i<=length3;i++){
if((sql3.charAt(i)<49)||((sql3.charAt(i)>54)&&(sql3.charAt(i)<65))||((sql3.charAt(i)>90)&&(sql3.charAt(i)<97))||(sql3.charAt(i)>122))
{
System.out.println("not the real character");
}
}
}
} );
anchorpane.getChildren().addAll(btn, text,textf,text2,textf2,text3,textf3);
primaryStage.setScene(new Scene(anchorpane, 550, 400));
primaryStage.show();
}
}
![]()
当换成三个框时的代码与界面如上,下面是测试用例: