13. ภายใน class TestObj จะมี code ดังนี้
public class TestObj {
private String firstName;
private String lastName;
public void showName() {
System.out.println("THIS IS METHOD
showName()");
System.out.println("My name is "+firstName+"
"+lastName);
}
}
14. จะเห็นได้ว่า Attribute ใน Class TestObj เป็น private ฉะนั้นก็จะต้อง
มี Getter and Setter เราสามารถที่จะสั่ง
ให้ NetBeans สร้าง Getter and Setter จากAttribute ที่มีอยู่ได้
โดยการคลิกขวาที่หน้าจอที่ใช้เขียน code แล้วเลือก Insert Code จะปรากฏ
หน้าต่างขึ้นมาให้เลือกที่ Getter and Setter
15. หน้าต่างสาหรับการ Generate Getters and Setters จะขึ้นมา ให้เราทา
การเลือกว่าจะสร้าง Getters and Setters ให้กับ Attribute ใดบ้าง เมื่อ
เลือกเสร็จเรียบร้อยให้กดGenerate
16. เราจะได้ code ของ class TestObj ดังนี้
public class TestObj {
private String firstName;
private String lastName;
public void showName() {
System.out.println("THIS IS METHOD showName()");
System.out.println("My name is "+firstName+" "+lastName);
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
17. นอกจากการ Generate Getters and Setters แล้ว เราสามารถคลิกขวาเพื่อดู Function อื่นๆ
ที่ NetBeans สามารถช่วยจัดการให้การทางานของเราง่ายขึ้น
เมื่อได้ class TestObj แล้ว ต่อไปเราก็ทาการแก้ไข code ของ MainClass ให้เป็นดังนี้
public class MainClass {
public static void main(String[] args) {
TestObj temp = new TestObj();
temp.setFirstName("Itthi");
temp.setLastName("Kruenarongkul");
temp.showName();
temp.setFirstName("Monthinee");
temp.setLastName("Buntawee");
temp.showName();
}
}
38. ทดสอยกำรเรียกใช้ Toolbox และกำรสร้ำง Element
ทดสอบกำรลำก Element ลงใน Android ActivityXML Layout ในตัวอย่ำงจะลำก Plan Text ลงใน Form
สังเกตุว่ำเมื่อมีกำรลำก Element ที่มีชื่อว่ำ Plan Text ลงใน Android ActivityForm ในส่วนของ Outline จะมีกำรสร้ำงรำยกำร Element แสดงไว้ด้วย
39. กรณีที่มีกำรสร้ำง Element ลงใน ActivityForm ต่ำง ๆ ถ้ำมี Warning หรือ Error จะต้องทำกำรแก้ไขให้เรียบร้อย ในตัวอย่ำงจะมี Warning ชื่อ
ว่ำ This text field does not specify and inputType or a hine
41. สำหรับกำรแก้ไขขึ้นอยู่กับ Error หรือ Warning Message ว่ำอะไร ซึ่งในตัวอย่ำงน่ำจะหมำยถึง Plan Text ไม่มีกำรกำหนด inputType
ให้คลิกขวำที่ Element เลือก Show In -> Properties ดังรูป