// ------------------------------------------------------------------ // Importing Collections of Classes // ------------------------------------------------------------------ import java.awt.* ; import java.applet.* ; public class SubroutinesAndFunctions extends Applet { // ---------------------------------------------------------------- // Declaration of Variables // ---------------------------------------------------------------- TextField mytext1 ; TextField mytext2 ; int intNum1 ; int intNum2 ; int intSum ; // ---------------------------------------------------------------- // Init Block // ---------------------------------------------------------------- public void init() { mytext1 = new TextField(5) ; mytext2 = new TextField(5) ; add(mytext1) ; add(mytext2) ; } // ---------------------------------------------------------------- // Paint Block // ---------------------------------------------------------------- public void paint(Graphics g) { // ------------------------------------------------------------ // Subroutine Call // ------------------------------------------------------------ DrawInstructions(g) ; String strText1 ; String strText2 ; strText1 = mytext1.getText() ; strText2 = mytext2.getText() ; intNum1 = Integer.parseInt(strText1) ; intNum2 = Integer.parseInt(strText2) ; // ------------------------------------------------------------ // Function Call // ------------------------------------------------------------ intSum = AddTwoIntegers() ; String strResult ; strResult = "The Sum of the Integers is : " ; strResult += String.valueOf(intSum) ; g.drawString( strResult , 40 , 65 ) ; } // ---------------------------------------------------------------- // Action Block // ---------------------------------------------------------------- public boolean action(Event event , Object arg ) { repaint() ; return true ; } // ---------------------------------------------------------------- // Subroutine Definition // ---------------------------------------------------------------- void DrawInstructions(Graphics g) { g.drawString("Subroutine Example" , 40 , 50 ) ; } // ---------------------------------------------------------------- // Function Definition // ---------------------------------------------------------------- int AddTwoIntegers() { intSum = intNum1 + intNum2 ; return intSum ; } }