|
Class wizard
Class wizard is a tool that makes it easy and fast to generate code
for a class by spesifying the name and type og the datamembers.
A constructor, find (and set) functions, and a toString function are
generated automatically.
In this tutorial we are going to create a class called Person, and
which has three datamembers: Name, address and telephone, all of type String.
1. Press key in the program, you find this button om the left
in the program under the java tab.
2. In the dialog that pops up you can enter the name of the Class,
the names of the datamembers and of course the datamember types.
3. First select String in Datatype dropdown menu, and type
telephone, in the "Datamember name" field. Press "Add.." to
add the datamember to the list of datamembers :) If you want a
a set function to the code that is generated, click on the box
next to the datamember in the list. 4. Do the same as in 3,for the datamembers Address and Name. Press
OK to generate the code.
5. The code that are generated looks like this:
class Person {
private String name;
private String address;
private String telephone;
public Person(String startName, String startAddress, String startTelephone) {
name = startName;
address = startAddress;
telephone = startTelephone;
}
public String findName() {
return name;
}
public String find Address() {
return address;
}
public String find Telephone() {
return telephone;
}
public String toString() {
return "Person - "+" name: "+name+" address: "+address+" telephone: "+
telephone;
}
}
|
|
|