From 6092c1b7759562ca0ff118b3a19e2cc4865593a0 Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Tue, 2 May 2006 20:11:18 +0000 Subject: [PATCH] Agrego botonito Mitad y eventons. --- src/FrGraf.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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"); } -- 2.43.0