Moving a Class to a Different Package


If you want to place a class in a different package, you can use the IDE's refactoring features to move the class and then update references to that class automatically throughout your project.

To move a class:

  1. In the Projects window, drag the class from its current package to the package you want to place it in. (You can also use the Cut and Paste commands in the contextual menus or the corresponding keyboard shortcuts.)

  2. In the Move Class or Move Classes dialog box (shown in Figure 5-16), click Next after verifying that the To Package and This Class fields reflect the destination package and the class you are moving. (If you move multiple classes, a List of Classes text area is shown instead of the This Class field.)

    Figure 5-16. Move Classes dialog box

    If you have deselected the Preview All Changes checkbox, the changes are applied immediately.

    If you leave the Preview All Changes checkbox selected, the Refactoring window appears with a preview of the changes.

  3. In the Refactoring window (shown in Figure 5-17), look at the preview of the code to be changed. If there is a modification that you do not want to be made, deselect the checkbox next to the line for that change.

    Figure 5-17. Refactoring window

  4. Click Do Refactoring.

    If you later find that the refactoring has had some consequences that you would like to reverse, you can choose Refactor | Undo.

If you want to create a new package and move all of the classes in the old package to the new package, you can do an in-place rename of a package in the Projects window (or of a folder in the Files window).




NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 279

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net