What’s wrong with this code?

Assume that nameJTextField is a JTextField. Find the error(s) in the following code:
```
1 String name = nameJTextField.getText();
2
3 if name.equals( "John Doe" )
4 {
5 JOptionPane.showMessageDialog( "Welcome, John!",
6 JOptionPane.INFORMATION_MESSAGE )
7 }
```

1. Parentheses must be added around the if statement’s condition, name.equals( "John Doe" ). 2. The call to method JOptionPane.showMessageDialog has the wrong num- ber of arguments. An argument needs to be added before "Welcome, John!" that specifies where the dialog will be displayed on the screen. Another argument needs to be added after "Welcome, John!" that specifies the text that will display in the dialog’s title bar.
```
1 String name = nameJTextField.getText();
2
3 if ( name.equals( "John Doe" ) )
4 {
5 JOptionPane.showMessageDialog( null, "Welcome, John!",
6 "Welcome", JOptionPane.INFORMATION_MESSAGE );
7 }
```

Computer Science & Information Technology

You might also like to view...

By default File History keeps saved versions until space is needed

Indicate whether the statement is true or false

Computer Science & Information Technology

Which of the following statements about heavyweight components is false?

a. AWT components are not heavyweight components. b. Several Swing components are heavyweight components. c. The look-and-feel may vary across platforms. d. The functionality may vary across platforms.

Computer Science & Information Technology