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...

Draw a flowchart for the program fragments (no need to show start and stop)

``` DO UNTIL value = 9999 INPUT value IF value < 9999 THEN LET sum = sum + value LETn=n+1 END IF LOOP ```

Computer Science & Information Technology

A circular reference:

A) is a rule that governs the structure and components for functions. B) is an input such as a cell reference or a value needed to complete a function. C) occurs when a formula directly or indirectly refers to the cell containing the formula. D) is a predefined formula that performs a calculation.

Computer Science & Information Technology

A(n) ________ can be selected or deselected when the person using the form clicks the content control

Fill in the blank(s) with correct word

Computer Science & Information Technology

Which tab in Windows do you use to open a file?

A. New B. File C. Open D. Edit

Computer Science & Information Technology