public class FrGraf extends Frame implements Observer
{
private Panel panel;
+ private Button boton;
private Label label;
+ private Fraccion fraccion;
public FrGraf (Fraccion f)
{
+ fraccion = f;
+
panel = new Panel ();
label = new Label(f.toString (), Label.CENTER);
+ boton = new Button ("Mitad!");
panel.setLayout (new BorderLayout ());
panel.add (label, BorderLayout.CENTER);
+ panel.add (boton, BorderLayout.SOUTH);
add (panel, BorderLayout.CENTER );
setSize (500, 300);
f.addObserver (this);
}
+ public boolean action (Event evt, Object obj) {
+ if (evt.target.equals(boton)) {
+ fraccion.setDen ( fraccion.getDen()*2);
+ }
+
+ return true;
+ }
+
public void update(Observable obs, Object obj)
{
- if (obj instanceof Fraccion) {
- label.setText (obj.toString ());
+ if (obs instanceof Fraccion) {
+ label.setText (obs.toString ());
} else {
label.setText ("E");
}