Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- */
- School project: TOL103 [2010]
- Writes in names to an Array (btn1) and write
- them all out to textarea when button(btn2) is pushed
- Java Applet
- */
- import java.awt.*;
- import java.applet.*;
- public class Project_6_2 extends Applet {
- TextField txtf;
- TextArea txta;
- Button btn1, btn2;
- String[] array = new String[10];
- int counter=0;
- public void init()
- {
- txtf = new TextField(10);
- txta = new TextArea(10,15);
- btn1 = new Button("Add names");
- btn2 = new Button("Write out names");
- this.add(txtf); this.add(btn1);
- this.add(btn2); this.add(txta);
- }
- public boolean action(Event e, Object o)
- {
- if (e.target == btn1)
- {
- array[counter]= txtf.getText();
- counter++;
- txtf.setText("");
- return true;
- }
- if (e.target == btn2)
- {
- for (int i=0; i<counter; i++)
- {
- txta.appendText(array[i]+ "\n");
- }
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment