0

I have a problem making a program that uses the type String. I want my program to make a loop if the user don't enter his first name.

public class formregister {
public static void main(String[] args) {


String nama_depan = jTextField_FN.getText();

do

{JOptionPane.showMessageDialog(null,"Add your first name");

} while (first_name.equals(""));

How can I check if the user entered his first name and then proceed to another step, like asking for his last name?

SCouto
  • 7,808
  • 5
  • 32
  • 49
Moel_Chan
  • 1
  • 1
  • You can't use a Message Dialog for this in a loop. What you need is a **Input Dialog**. Read up on the [**JOptionPane.showInputDialog()**](https://www.homeandlearn.co.uk/java/java_option_panes.html) method. And the **while** condition should be changed to: `while (nama_depan.equals(""));` with the Input Dialog filling the variable within the loop. – DevilsHnd - 退職した Sep 09 '18 at 02:43
  • How about using `Scanner`? – Nicholas K Sep 09 '18 at 10:00

0 Answers0