Jump to content

Hello

 

Lets get right into the question

1)If i have 9 TextFields, and if one of them is empty, the empty field will be turn to yellow and if all of the textfield is filled, there will be a JOptionPane Message. How do i do that?

2)How to let the user can only input alphabet, space, and apostrof ( ` )

3)if there is a city field, which then the user input ("Surabaya") then the phone field will automatically filled with (+031) 

Link to comment
https://linustechtips.com/topic/324201-javaswing-questions/
Share on other sites

Link to post
Share on other sites

1. 

boolean flag = false;for (int i = 0; i < 9; i++) {    if (textField[i].getText().equals("")) {        textField[i].setBackground(Color.YELLOW);        flag = true;    }}if (!flag) {    // joptionpane code}

2. May have to use something like java swing formatted text fields. Or perhaps java's string matches method. I have used that to only allow numerical value with this code. 

heightTextField.getText().matches("[-+]?\\d+(\\.\\d+)?")

3.

if (cityTextField.getText().equals("Surabaya")) {    phoneTextField.setText("+301");}
Link to comment
https://linustechtips.com/topic/324201-javaswing-questions/#findComment-4406275
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×