/* */ import java.applet.Applet; import java.awt.Graphics; import java.awt.Color; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; public class Tomato extends Applet { public void init() { this.addMouseMotionListener(new Umpire()); } int n; public void paint(Graphics g) { g.setColor(Color.red); g.fillOval(50, 50, 300, 300); g.setColor(Color.green); g.drawOval(50, 50, 300, 300); this.n += 1; System.out.println("I am paint and I am working " + this.n); } } class Umpire implements MouseMotionListener { public void mouseMoved(MouseEvent e) { int x = e.getX(), y = e.getY(); System.out.println("I am moving the mouse...(" + x + ", " + y + ")"); } public void mouseDragged(MouseEvent e) { int x = e.getX(), y = e.getY(); System.out.println("Mouse being dragged (" + x + ", " + y + ")"); } } ----------------- Classes and objects are containers. Classes contain: a) blueprint for objects of that type b) static members (methods and variables) Objects are instantiations of blueprints and they contain: a) instance members (methods and variables) class One { int a; static int b; public static void main(String[] args) { One a = new One(); One b = new One(); a.a = 1; a.b += 2; b.a += 9; b.b += 4; System.out.println(a.a + ", " + b.b); System.out.println(b.a + ", " + b.b); } } The class extension mechanism: inheritance, polymorphism, dynamic method lookup. The meaning of "this": a) if we had only variables "this" wouldn't be, couldn't exist b) "this" can be used and makes sense only from inside a method c) "this" can't appear in a static method, it is not allowed, not accepted d) "this" therefore can only appear in an instance method, where it refers to the instance where that method is.