GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: Add Line Numbers


applet by jen

/* importing stuff */ import javax.swing.*; import java.awt.*; import java.awt.event.*; /* defining the class - MultipleApplet */ public class MultipleApplet extends JApplet implements ActionListener {      /* creating fields and labels */      JLabel label1, label2, resultlabel;      JTextField field1, field2, resultfield;      /* main method - begin execution */      public void init()      {         /* setting up the windows and stuff */         Container container = getContentPane();         container.setLayout( new FlowLayout() );         /* creating labels */         label1 = new JLabel ( "Please type an integer." );         label2 = new JLabel ( "Type another and press Enter." );         resultlabel = new JLabel ( "Results: " );         /* attaching labels to container */         container.add( label1 );         container.add( label2 );         container.add( resultlabel );         /* creating fields */         field1 = new JTextField( 10 );         field2 = new JTextField( 10 );         resultfield = new JTextField( 35 );         /* attaching fields to container */         container.add( field1 );         container.add( field2 );         container.add( resultlabel );         /* make result uneditable */         resultfield.setEditable( false );         /* making the second input listening */         field2.addActionListener( this );          System.exit ( 0 ); /* termination! */      } /* end of main method */      /* defining the method - actionPerformed */      public void actionPerformed( ActionEvent event ) {          /* input will be parsed to these  */         int num1;         int num2;          /* defining other stuff */         boolean mult;         String result;          /* parsing user input into array */          num1 = Integer.parseInt( field1.getText() );         num2 = Integer.parseInt( field2.getText() );         /* status thing */         showStatus ( "Calculating.." );          /* method call */          mult = findMult( num1, num2 );          /* creating true result string */          if ( mult == true ) {             result = num2 + " is a multiple of " + num1;         }         /* creating false result string */         else {             result = num2 + " is not a multiple of " + num1;         }         /* status thing again */         showStatus ( "Done." );         /* displaying result */         resultfield.setText( result );     } /* end of actionPerformed method */      /* defining the method - findMult */      public boolean findMult( int num1, int num2 )      {         int remainder;         int number1 = num1;         int number2 = num2;         /* determine the remainder  */         remainder = number2 % number1;         /* if no remainder, return true */         if ( remainder == 0) {             return true;         }         /* otherwise return false */         else {             return false;         }     } /* end method findMult */ } /* end of program :) */