//**************************************************************** // TRABAJO ISBC : INTEGRACION JAVA-JESS. CASO DEL ELEVADOR //**************************************************************** // // Fichero: CanvasPiso.java // Autor: David Portoles // Proposito: Contiene la clase CanvasPiso que representa // graficamente los pasajeros que esperan en un piso // //**************************************************************** import java.awt.*; import java.util.*; public class CanvasPiso extends Canvas { int numPasajeros; int numPiso; public CanvasPiso(int numPiso) { numPasajeros = 0; this.numPiso = numPiso; setSize(70,40); setBackground(Color.white); } public void addPasajero() { numPasajeros++; this.validate(); this.repaint(); } public void removePasajero() { numPasajeros--; this.validate(); this.repaint(); } public void paint(Graphics g) { g.setColor(Color.white); g.fillRect(0, 0, this.getWidth(), this.getHeight()); //le dibujo el fondo g.setColor(Color.black); g.drawRect(0, 0, this.getWidth(), this.getHeight()); //le dibujo el marco g.drawString(this.numPiso + "", 2, 14); // pongo el numero del piso //algunos de estos valores habria q intentar hacerlos mas generales int x = 14; //dejo un hueco para no machacar el numero del piso for (int j = 0; j < numPasajeros; j++) { g.drawOval(x+3, 10, 4, 4); // cabeza g.drawLine(x, 20, x+10, 20); // brazos g.drawLine(x+5, 15, x+5, 25); // tronco g.drawLine(x+5, 25, x+2, 30); // pierna izda g.drawLine(x+5, 25, x+8, 30); // pierna dcha x = x + 14; } } }