Home » Archimedes archive » Acorn User » AU 1998-13 (Christmas).adf » Features » Java/Ex1_java

Java/Ex1_java

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Acorn User » AU 1998-13 (Christmas).adf » Features
Filename: Java/Ex1_java
Read OK:
File size: 0203 bytes
Load address: 0000
Exec address: 0000
File contents
import java.applet.Applet;
import java.awt.*;

public class Ex1 extends Applet {

  Label label1;
  TextField text1;
  Button button1;

  public void init() {
    label1 = new Label("Text field:");
    add(label1);
    text1 = new TextField(10);
    add(text1);
    button1 = new Button("Click here");
    add(button1);
  }

  public boolean action(Event e, Object arg) {
    Object target = e.target;
    if (target == button1) {
      text1.setText("Thank you");
      return true;
    }
    return false;
  }

}
00000000  69 6d 70 6f 72 74 20 6a  61 76 61 2e 61 70 70 6c  |import java.appl|
00000010  65 74 2e 41 70 70 6c 65  74 3b 0a 69 6d 70 6f 72  |et.Applet;.impor|
00000020  74 20 6a 61 76 61 2e 61  77 74 2e 2a 3b 0a 0a 70  |t java.awt.*;..p|
00000030  75 62 6c 69 63 20 63 6c  61 73 73 20 45 78 31 20  |ublic class Ex1 |
00000040  65 78 74 65 6e 64 73 20  41 70 70 6c 65 74 20 7b  |extends Applet {|
00000050  0a 0a 20 20 4c 61 62 65  6c 20 6c 61 62 65 6c 31  |..  Label label1|
00000060  3b 0a 20 20 54 65 78 74  46 69 65 6c 64 20 74 65  |;.  TextField te|
00000070  78 74 31 3b 0a 20 20 42  75 74 74 6f 6e 20 62 75  |xt1;.  Button bu|
00000080  74 74 6f 6e 31 3b 0a 0a  20 20 70 75 62 6c 69 63  |tton1;..  public|
00000090  20 76 6f 69 64 20 69 6e  69 74 28 29 20 7b 0a 20  | void init() {. |
000000a0  20 20 20 6c 61 62 65 6c  31 20 3d 20 6e 65 77 20  |   label1 = new |
000000b0  4c 61 62 65 6c 28 22 54  65 78 74 20 66 69 65 6c  |Label("Text fiel|
000000c0  64 3a 22 29 3b 0a 20 20  20 20 61 64 64 28 6c 61  |d:");.    add(la|
000000d0  62 65 6c 31 29 3b 0a 20  20 20 20 74 65 78 74 31  |bel1);.    text1|
000000e0  20 3d 20 6e 65 77 20 54  65 78 74 46 69 65 6c 64  | = new TextField|
000000f0  28 31 30 29 3b 0a 20 20  20 20 61 64 64 28 74 65  |(10);.    add(te|
00000100  78 74 31 29 3b 0a 20 20  20 20 62 75 74 74 6f 6e  |xt1);.    button|
00000110  31 20 3d 20 6e 65 77 20  42 75 74 74 6f 6e 28 22  |1 = new Button("|
00000120  43 6c 69 63 6b 20 68 65  72 65 22 29 3b 0a 20 20  |Click here");.  |
00000130  20 20 61 64 64 28 62 75  74 74 6f 6e 31 29 3b 0a  |  add(button1);.|
00000140  20 20 7d 0a 0a 20 20 70  75 62 6c 69 63 20 62 6f  |  }..  public bo|
00000150  6f 6c 65 61 6e 20 61 63  74 69 6f 6e 28 45 76 65  |olean action(Eve|
00000160  6e 74 20 65 2c 20 4f 62  6a 65 63 74 20 61 72 67  |nt e, Object arg|
00000170  29 20 7b 0a 20 20 20 20  4f 62 6a 65 63 74 20 74  |) {.    Object t|
00000180  61 72 67 65 74 20 3d 20  65 2e 74 61 72 67 65 74  |arget = e.target|
00000190  3b 0a 20 20 20 20 69 66  20 28 74 61 72 67 65 74  |;.    if (target|
000001a0  20 3d 3d 20 62 75 74 74  6f 6e 31 29 20 7b 0a 20  | == button1) {. |
000001b0  20 20 20 20 20 74 65 78  74 31 2e 73 65 74 54 65  |     text1.setTe|
000001c0  78 74 28 22 54 68 61 6e  6b 20 79 6f 75 22 29 3b  |xt("Thank you");|
000001d0  0a 20 20 20 20 20 20 72  65 74 75 72 6e 20 74 72  |.      return tr|
000001e0  75 65 3b 0a 20 20 20 20  7d 0a 20 20 20 20 72 65  |ue;.    }.    re|
000001f0  74 75 72 6e 20 66 61 6c  73 65 3b 0a 20 20 7d 0a  |turn false;.  }.|
00000200  0a 7d 0a                                          |.}.|
00000203