--- /dev/null
+
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+
+public class AngCanvas extends Canvas implements Observer
+{
+ private int radianes;
+
+ public AngCanvas (Angulo g) {
+ radianes = g.getGrados ();
+ }
+
+ public void paint(Graphics g) {
+ g.setColor(Color.BLACK);
+ g.fillRect(0, 0, 400, 400);
+ g.setColor( Color.RED );
+ g.fillArc(100, 100, 200 , 200, 0, radianes);
+ System.out.println (radianes);
+ }
+
+ public Dimension getPreferredSize(){
+ return new Dimension (400, 400);
+ }
+
+ public void update(Observable obs, Object obj)
+ {
+ if (obs instanceof Angulo) {
+ radianes = ((Angulo)obs).getGrados ();
+ }
+ repaint ();
+ }
+}
+
--- /dev/null
+
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+
+public class AngGraf extends Frame implements Observer
+{
+ private Panel panel;
+ private Button boton;
+ private Label label;
+ private AngCanvas canvas;
+ private Angulo angulo;
+
+ public AngGraf (Angulo f)
+ {
+ angulo = f;
+
+ panel = new Panel ();
+ label = new Label(f.toString (), Label.CENTER);
+ boton = new Button ("Mitad!");
+ canvas = new AngCanvas (f);
+
+ panel.setLayout (new BorderLayout ());
+ panel.add (label, BorderLayout.NORTH);
+ panel.add (canvas, BorderLayout.CENTER);
+ panel.add (boton, BorderLayout.SOUTH);
+
+ add (panel, BorderLayout.CENTER );
+ setSize (500, 300);
+ setVisible (true);
+
+ f.addObserver (this);
+ f.addObserver (canvas);
+ }
+
+ public boolean action (Event evt, Object obj) {
+ if (evt.target.equals(boton)) {
+ angulo.fromRadianes ( angulo.toRadianes () / 2);
+ }
+
+ return true;
+ }
+
+ public void update(Observable obs, Object obj)
+ {
+ label.setText (obs.toString ());
+ }
+
+ static public void main (String[] args) {
+ Angulo modelo = null;
+ try {
+ modelo = new Angulo (359, 0, 0);
+ }
+ catch (Exception e) {
+ }
+
+ AngGraf vista = new AngGraf (modelo);
+ }
+}
+import java.util.*;
-public class Angulo implements OperAng, ComparaAng {
+public class Angulo extends Observable implements OperAng, ComparaAng {
private int signo;
private int grados;
signo = -1;
else
signo = 1;
+ setChanged ();
+ notifyObservers ();
}
public void setGrados(int g) {
setSigno(g);
grados = Math.abs(g % 360);
+ setChanged ();
+ notifyObservers ();
}
public void setMinutos(int m) {
minutos = Math.abs(m % 60);
+ setChanged ();
+ notifyObservers ();
}
public void setSegundos(int s) {
segundos = Math.abs(s % 60);
+ setChanged ();
+ notifyObservers ();
}
public Angulo() {