/* Copyright F. P. Marin ( July 22 18:11:20 1998 ) E-mail: felix@bloch.ciens.ucv.ve Permission to use, copy, modify and distribute this software and its documentation for NON-COMERCIAL purposes and without fee is hereby granted provided that this copyright notice appears in all copies. F. P. Marin makes no representations or warranties about the suitability of the software, either express or implied, including but no limited to the implied warranties of merchantability, fitness for a particular purpose, or non-infringement. F. P. Marin shall not be liable for any damage suffered by license as a result of using, modifying or distributing this software or its derivatives. Html code: */ import java.awt.*; public class Gcd extends java.applet.Applet { Button b=new Button("Gcd = "); Label l[]=new Label[2]; TextField tf[]=new TextField[3]; public void init() { setLayout(new GridLayout(3,2)); l[0]=new Label("A number = ",Label.RIGHT); l[1]=new Label("Another number = ",Label.RIGHT); tf[0]=new TextField(20); tf[1]=new TextField(20); tf[2]=new TextField(20); add(l[0]); add(tf[0]); add(l[1]); add(tf[1]); add(b); add(tf[2]); } // action implements the Euclides algorithm // public boolean action(Event e,Object arg) { if ( e.target!=b ) return true; tf[2].setText(""); long u=0L; try { u=Long.parseLong(tf[0].getText()); } catch ( NumberFormatException nfe ) { tf[0].setText(""); } long v=0L; try { v=Long.parseLong(tf[1].getText()); } catch ( NumberFormatException nfe ) { tf[1].setText(""); } u=Math.abs(u); v=Math.abs(v); if ( v!=0L ) { for ( long temp ; (u%=v)!=0L ; ) { temp=u; u=v; v=temp; } tf[2].setText(v + ""); } else if ( u!=0L ) { tf[1].setText("0"); tf[2].setText(u + ""); } else { tf[0].setText(""); tf[1].setText(""); } return true; } }