30
Sep
// paint all rectangles void paint(Graphics g) {
public void paint(Graphics g) { g.setColor(myColor); g.fillRect(locx,locy,width,height); } } The this Keyword Let s look inside the constructor method of DancingRect. (Remember that a constructor is a method with the same name as the class, with no return type.) What is this? public DancingRect(int locx,int locy, int width,int height, Color myColor) { this.locx = locx; this.locy = locy; … } An object encapsulates variables and methods, and this is a reference to this particular object that the variable or method belongs to. Each variable in a method definition is preceded by an implied this (unless it s a member of an explicitly stated object). Thus, the paint() method defined above is shorthand for public void paint(Graphics g) { g.setColor(this.myColor); g.fillRect(this.locx,this.locy,this.width,this.height); } Previous Table of Contents Next
Note: If you are looking for top 10 and very good webhost to host and run your jsp application check Actions jsp hosting services
