![]() Now that you have a working program, read about how to submit your homework in the next tutorial. If you want to rename a class, you MUST use refactor because there are many dependencies on class names. You can refactor methods, variables, and other things as well. If you go back to the Driver class, you will notice that "p.displayName" was automatically changed to "p.printName":.This is showing you all the places where it will change the "displayName" method to "printName" instead. At the bottom of the IDE, you will notice a Refactoring window has appeared.For the "New Name" field, change it from "displayName" to "printName" and click the "Next" button.Select Refactor > Rename from the menu at the top.Go to the Person class and highlight the "displayName" in the method declaration:.This is simple, but one problem occurs: we have to change every place that called "displayName" as well. We would like to change it to "printName" instead. Lets say we are not happy with the name we gave the method "displayName" in the Person class. Step 4: Using the Netbeans "Refactor" feature If we run our program, we should see the output from our old tutorial and the name "Mike" printed to the console:.All you need to do is add the closing parenthesis and semi-colon. If you press enter, auto-complete will type it automatically for you. You will notice that the method "displayName" is listed as the top one.On the next line, if you type "p.", you will see a list of methods that are available: Now that we have a Person instance, lets see what methods we can call on it.We will just leave the old code from the previous tutorials. In the "main" method of our Driver class, lets create a Person named "Mike". Since we now have the Person class, lets make some use out of it. Step 3: Using intellisense & auto-complete with the classes you create ![]() Lets also write a method called "displayName" which will just print the name out.Lets make a constructor that takes a String and sets the name to be that String.Lets give the Person class a member variable called "name".Step 2: Make the Person class do something You should also get a warning at the bottom about putting new classes in the default package. If it is not, please read the note in Tutorial 3, Step 1. Click on the "Finish" button when you are done Name the class "Person" and leave all the other fields alone.At the New File screen, select "Java Classes" for Category, "Java Class" for the File Type and click the "Next" button.Select File > New File from the menu at the top. ![]() This tutorial deals with how to add another java class to your project, how Intellisense learns about the classes you are creating, and how to use the NetBeans "Refactor" Then press 'Insert' key and the 'override' cursor will have the new color. A yet better workaround: set the desired color (Caret color, Caret color (override)), accept and go back to editor. Tutorial 5 - Adding another Java class to a project 1 2 3 4 5 6 7 The trick is to click Apply (doing and undoing any other change) from this tab so the cursor setting will make effect.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |