ETE

Project TOL103

ETE
Mar 11th, 2011
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. */
  2. School project: TOL103 [2010]
  3. Writes in names to an Array (btn1) and write
  4. them all out to textarea when button(btn2) is pushed
  5. Java Applet
  6. */
  7.  
  8. import java.awt.*;
  9. import java.applet.*;
  10.  
  11. public class Project_6_2 extends Applet {
  12.    
  13.     TextField txtf;
  14.     TextArea txta;
  15.     Button btn1, btn2;
  16.     String[] array = new String[10];
  17.     int counter=0;
  18.    
  19.     public void init()
  20.         {
  21.     txtf = new TextField(10);
  22.     txta = new TextArea(10,15);
  23.     btn1 = new Button("Add names");
  24.     btn2 = new Button("Write out names");
  25.  
  26.     this.add(txtf); this.add(btn1);
  27.     this.add(btn2); this.add(txta);
  28.     }  
  29.  
  30.     public boolean action(Event e, Object o)
  31.     {
  32.        if (e.target == btn1)
  33.        {
  34.         array[counter]= txtf.getText();
  35.         counter++;
  36.         txtf.setText("");
  37.         return true;
  38.        }   
  39.        if (e.target == btn2)
  40.        {
  41.            for (int i=0; i<counter; i++)
  42.            {   
  43.                 txta.appendText(array[i]+ "\n");
  44.            }
  45.                return true;
  46.        }
  47.     return false;
  48.     }  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment