NombreDelPrograma.java
Categorías: CategoryJava | CategoryProgramacion |
1 package buddypocket;
2
3 import java.awt.Graphics;
4 import java.awt.Rectangle;
5 import java.io.Serializable;
6
7 /**
8 * es la clase factoriza
9 * las caracteristicas comunes entre
10 * clases y clases
11 *
12 * @author Jennifer
13 */
14
15 public abstract class ObjetoGrafico implements Serializable {
16
17 protected boolean visible; // false o true
18 protected int x,y,ancho,alto;
19 public ObjetoGrafico(int x, int y, int ancho, int alto){
20 this.x=x;
21 this.y=y;
22 this.ancho=ancho;
23 this.alto=alto;
24 visible = true;
25 }
26 public abstract void paint(Graphics g);
27 public void incx (int dx){
28 x+=dx;
29 }
30 public void decx(int dx){
31 x-=dx;
32 }
33 public void incy (int dy){
34 y+=dy;
35 }
36 public void decy(int dy){
37 y-=dy;
38 }
39
40
41
42
43 /**
44 * metodo para la coliion entre el valde y las bolas
45 *
46 *
47
48 */
49
50 public boolean colisiona(ObjetoGrafico otro){
51 if (this == otro) {
52 return false;
53 }
54 Rectangle r1= new Rectangle (this.x, this.y, this.ancho, this.alto);
55 Rectangle r2 = new Rectangle (otro.x, otro.y, otro.ancho, otro.alto);
56
57
58 return r1.intersects(r2);
59
60 }
61
62 public void setVisible(boolean visible) {
63 this.visible = visible;
64 }
65
66 public void setX(int x) {
67 this.x = x;
68 }
69
70
71 }
72
73
74
75
76
77
