import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.text.*; public class Gcd extends Applet implements ActionListener { Label label1, label2, title; TextField input1, input2; int a, b, gcd; public void init () { title = new Label ("GCD calculator (type numbers and press Enter)"); label1 = new Label ("First number: "); label2 = new Label ("Second number: "); input1 = new TextField (6); input2 = new TextField (6); add (title); add (label1); add (input1); add (label2); add (input2); input1.addActionListener(this); input2.addActionListener(this); a = 0; b = 0; } public void paint ( Graphics page ) { page.drawString( "GCD of " + a + " and " + b + " is " + gcd, 40, 50); } public void actionPerformed (ActionEvent e) { a = Integer.parseInt(input1.getText()); b = Integer.parseInt(input2.getText()); gcd = euclid(a,b); repaint(); } public int euclid (int x, int y) { int t; while (y>0) { t = x % y; x = y; y = t; } return x; } }