From: Ricardo Markiewicz Date: Tue, 2 May 2006 20:11:18 +0000 (+0000) Subject: Agrego botonito Mitad y eventons. X-Git-Tag: darcs_import~4 X-Git-Url: https://git.llucax.com/z.facultad/75.62/c2tp1.git/commitdiff_plain/6092c1b7759562ca0ff118b3a19e2cc4865593a0 Agrego botonito Mitad y eventons. --- diff --git a/src/FrGraf.java b/src/FrGraf.java index b81eb65..8cda387 100644 --- a/src/FrGraf.java +++ b/src/FrGraf.java @@ -6,15 +6,21 @@ import java.util.*; 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); @@ -23,10 +29,18 @@ public class FrGraf extends Frame implements Observer 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"); }