Three-Box EditBox

Source: Internet
Author: User
Tags control characters

First, the procedure requirements

EditBox also allows you to enter three 1 to 6 English characters or numbers and click OK to finish.

Two, effective equivalence class and invalid equivalence class division

Valid equivalence classes

Invalid equivalence class

E1: Length: 1 to 6

T1: Length: 0 or >=7

E2: Character: a-z,a-z,0-9

T2: Characters: English, characters other than numbers, control characters, punctuation marks, such as/. , such as punctuation

Third, the test case design, according to valid and invalid equivalence class can design 6 test cases

Coding First box input Second box input Third box input Results
1 Empty Empty Empty The input format is not correct
2 123 Asd 123asd Enter the correct
3 1234567 Asd 123asd The first input is in an incorrect format
4 123456 12345asd Asdf The second input is in an incorrect format
5 Asdfg 123asd Zxcv , The third input format is incorrect
6 Asd 1234567 123asdfg Only the first one is correctly entered

Iv. program code: using JAVAFX implementation

1 Importjavafx.application.Application;2 Importjavafx.event.ActionEvent;3 ImportJavafx.event.EventHandler;4 ImportJavafx.scene.Scene;5 ImportJavafx.scene.control.Button;6 ImportJavafx.scene.control.TextField;7 ImportJavafx.scene.layout.AnchorPane;8 ImportJavafx.scene.text.Text;9 ImportJavafx.stage.Stage;Ten  One  A  Public classEditBoxextendsapplication{ -      Public Static voidMain (String arg0[]) { - Testtest.launch (arg0); the     } -      Public voidStart (Stage stage)throwsException { -Stage.settitle ("EditBox"); -Anchorpane root =NewAnchorpane (); +Scene scene =NewScene (root,500,400); -          +Text Text =NewText ("Please enter string:");  AAnchorpane.setleftanchor (text, 150.0); atAnchorpane.settopanchor (text,50.0); -          -         FinalTextField INPUT1 =NewTextField (); -         FinalTextField Input2 =NewTextField (); -         FinalTextField INPUT3 =NewTextField (); -Anchorpane.setleftanchor (input1,150.0); inAnchorpane.setleftanchor (input2,150.0); -Anchorpane.setleftanchor (input3,150.0); toAnchorpane.settopanchor (input1,100.0); +Anchorpane.settopanchor (input2,150.0); -Anchorpane.settopanchor (input3,200.0); the          *Button check =NewButton (); $Check.settext ("OK");Panax NotoginsengAnchorpane.setleftanchor (check, 150.0); -Anchorpane.settopanchor (check, 250.0); the          +Check.setonaction (NewEventhandler<actionevent>(){ A  the @Override +              Public voidhandle (ActionEvent arg0) { -                 if(Stringcheck (Input1.gettext (). toString ()) && $Stringcheck (Input2.gettext (). toString ()) &&Stringcheck (Input3.gettext (). toString ())) { $Stage correct =NewStage (); -Anchorpane Correctroot =NewAnchorpane (); -Text correcttext =NewText ("Input correct"); theAnchorpane.setleftanchor (Correcttext, 80.0); -Anchorpane.settopanchor (Correcttext, 40.0);Wuyi Correctroot.getchildren (). Add (correcttext); theScene Scene2 =NewScene (correctroot,200,100); - Correct.setscene (scene2); Wu correct.show (); -                 } About                 Else if(! (Stringcheck (Input1.gettext (). toString ()) && $Stringcheck (Input2.gettext (). toString ()) &&Stringcheck (Input3.gettext (). toString ()))) { -Stage result =NewStage (); -Anchorpane error =NewAnchorpane ();  -                     if(Stringcheck (Input1.gettext (). toString ()) &&Stringcheck (Input2.gettext (). toString ())) { AText correcttext =NewText ("Third input format is incorrect"); +Anchorpane.setleftanchor (Correcttext, 30.0); theAnchorpane.settopanchor (Correcttext, 30.0); - Error.getchildren (). Add (Correcttext);  $                     }     the                     Else if(Stringcheck (Input2.gettext (). toString ()) &&Stringcheck (Input3.gettext (). toString ())) { theText correcttext =NewText ("The first input format is incorrect"); theAnchorpane.setleftanchor (Correcttext, 30.0); theAnchorpane.settopanchor (Correcttext, 30.0); - Error.getchildren (). Add (correcttext); in                     } the                     Else if(Stringcheck (Input1.gettext (). toString ()) &&Stringcheck (Input3.gettext (). toString ())) { theText correcttext =NewText ("2nd input format is incorrect"); AboutAnchorpane.setleftanchor (Correcttext, 30.0); theAnchorpane.settopanchor (Correcttext, 30.0); the Error.getchildren (). Add (correcttext); the                     } +                     Else if(Stringcheck (Input1.gettext (). toString ())) { -Text correcttext =NewText ("Only 1th input format is correct"); theAnchorpane.setleftanchor (Correcttext, 30.0);BayiAnchorpane.settopanchor (Correcttext, 30.0); the Error.getchildren (). Add (correcttext); the                     } -                     Else if(Stringcheck (Input2.gettext (). toString ())) { -Text correcttext =NewText ("Only 2nd input format is correct"); theAnchorpane.setleftanchor (Correcttext, 30.0); theAnchorpane.settopanchor (Correcttext, 30.0); the Error.getchildren (). Add (correcttext); the                     } -                     Else if(Stringcheck (Input3.gettext (). toString ())) { theText correcttext =NewText ("Only 3rd input format is correct"); theAnchorpane.setleftanchor (Correcttext, 30.0); theAnchorpane.settopanchor (Correcttext, 30.0);94 Error.getchildren (). Add (correcttext); the                     } the                     Else{ theText correcttext =NewText ("Input format is not correct");98Anchorpane.setleftanchor (Correcttext, 30.0); AboutAnchorpane.settopanchor (Correcttext, 30.0); - Error.getchildren (). Add (correcttext);101                     }102Scene Scene2 =NewScene (error,200,100);103 Result.setscene (scene2);104 result.show (); the                 }106             }107             108         });109          the Root.getchildren (). AddAll (Text,input1,input2,input3,check);111 stage.setscene (scene); the stage.show ();113     } the      Public Booleanstringcheck (String ch) { the         if(Ch.length () ==0 | | ch.length () >6){ the             return false;117         }118         CharArr[] =New Char[Ch.length ()];119arr =Ch.tochararray (); -          for(intI=0;i<ch.length (); i++){121             if((Arr[i] >= ' A ' && arr[i] <= ' z ') | | (Arr[i] >= ' A ' && arr[i] <= ' Z ') | | (Arr[i] >= ' 0 ' && arr[i] <= ' 9 ')); 122             Else{123                 return false;124                 } the         }126         return true;127     } - 129}

V. Procedures

Three-Box EditBox

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.