home *** CD-ROM | disk | FTP | other *** search
/ Java by Example / jbecd.bin / JBE-CD / NTUsers / JBECODE.ZIP / JavaByExample / chap36 / StringApplet.java < prev    next >
Encoding:
Java Source  |  1996-03-26  |  1.2 KB  |  49 lines

  1. import java.awt.*;
  2. import java.applet.*;
  3.  
  4. public class StringApplet extends Applet
  5. {
  6.     TextField textField1;
  7.     TextField textField2;
  8.  
  9.     public void init()
  10.     {
  11.         textField1 = new TextField(20);
  12.         textField2 = new TextField(20);
  13.  
  14.         textField1.setText("STRING");
  15.         textField2.setText("String");
  16.  
  17.         add(textField1);
  18.         add(textField2);
  19.     }
  20.  
  21.     public void paint(Graphics g)
  22.     {
  23.         String str1 = textField1.getText();
  24.         String str2 = textField2.getText();
  25.         
  26.         boolean equal = str1.equalsIgnoreCase(str2);
  27.         if (equal)
  28.             g.drawString("The strings are equal.", 70, 100);
  29.         else
  30.             g.drawString("The strings are not equal.", 70, 100);
  31.  
  32.         String newStr = str1.concat(str2);
  33.  
  34.         g.drawString("JOINED STRINGS:", 70, 130);
  35.         g.drawString(newStr, 80, 150);
  36.  
  37.         g.drawString("STRING LENGTH:", 70, 180);
  38.         int length = newStr.length();
  39.         String s = String.valueOf(length);
  40.         g.drawString(s, 80, 200);
  41.     }
  42.  
  43.     public boolean action(Event evt, Object arg)
  44.     {
  45.         repaint();
  46.         return true;
  47.     }
  48. }
  49.