FIGURA.
JAVA
public void setX(int x) { this.x = x;
package pckherenciafigura;
import java.awt.Graphics; public abstract class Figura { private String nombre; private int x; private int y;
public int getY() { return y; }
public void setY(int y) { this.y = y;
public abstract void dibujar(Graphics g); public String getNombre() { return nombre; } }
public void setNombre(String nombre) { this.nombre = nombre; }
public int getX() { return x; }
FIGURA2D
package pckherenciafigura;
FIGURA3D
package pckherenciafigura;
/** * * @author Administrador */ public abstract class Figura2D extends Figura {
/** * * @author Administrador */ public abstract class Figura3D extends Figura {
public abstract double area(); public abstract double perimetro(); } }
public abstract double volumen();
MAIN.JAVA
package pckherenciafigura; public class Main { public static void main(String[] args) {
java.awt.EventQueue.invokeLater( new Runnable() { public void run() { new FrmFiguras().setVisible(true); } }); } }
CIRCULO.JAVA
package pckherenciafigura; public double area() { return ( Math.PI * radio * radio ); import java.awt.Graphics; }
public class Circulo extends Figura2D {
//Circunferencia public double perimetro() {
private double radio; } public Circulo(double radio) { setNombre("Circulo"); setX(0); setY(0); this.radio = radio; } }
return (2 * Math.PI * radio);
public double diametro() { return (2 * radio);
public void dibujar(Graphics g) { g.drawOval( getX(), getY(), (int)radio, (int)radio);
public double getRadio() { return radio; } }
public void setRadio(double radio) { this.radio = radio; }
TRIANGULO.JAVA
} package pckherenciafigura; import java.awt.Graphics;
this.alto = alto;
public double getAncho() { return ancho;
public class Rectangulo extends Figura2D {
} public void setAncho(double ancho) { this.ancho = ancho;
private double ancho; private double alto;
} public double area() { return (ancho * alto);
public Rectangulo(double ancho, double alto) { setNombre("Rectangulo"); setX(0); setY(0); this.ancho = ancho; this.alto = alto; }
} public double perimetro() { return (2 * ancho + 2 * alto); } public void dibujar(Graphics g) { g.drawRect(getX(), getY(), (int)ancho, (int)alto); }
public double getAlto() { return alto; } }
public void setAlto(double alto) {