Add the source code to the project

Follow these steps to add the source to the project.

  1. Open the following source code, select all, and copy it to the clipboard: MainApp.java.
  2. Add the Java source file with Eclipse or NetBeans.

Option 1: Eclipse

  1. In the Package Explorer view, select the project and right-click.

  2. From the context menu, select New > Class. The New Java Class wizard opens.

  3. Type the Name of the class: MainApp.

  4. Click Finish.

  5. The MainApp.java file is automatically opened in the editor. Replace its contents with the source code you copied in the previous step.

  6. A line at the top of the pasted code is underlined in red. Click on that line; a pop-up appears. Select the first option (Move 'MainApp.java' to package '...') to resolve the error.

Option 2: NetBeans

  1. In the Projects view, select the project and right-click.

  2. From the context menu, select New > Java Class... The New Java Class wizard opens.

  3. Modify the Class Name to be MainApp.

  4. Click Finish.

  5. The MainApp.java file automatically opens in the editor. Replace its contents with the source code you copied in the previous step.

  6. A line at the top of the pasted code is underlined in red. Click on the light bulb next to that line; a pop-up appears. Select the first option (Move class to correct folder) to resolve the error.