Code Sample 37_1
import java.applet.*;
import java.awt.*;
public class clickcount extends Applet {
int count;
TextField f;
public void init() {
setBackground(Color.white);
count = 0;
add(new Button("Click Here"));
f = new TextField("The button has not been clicked at all.");
f.setEditable(false);
add(f);
}
public boolean action(Event e, Object arg) {
if (((Button) e.target).getLabel() == "Click Here") {
count += 1;
f.setText("The button has been clicked " + count + " times.");
}
return true;
}
}
Item information
| Caption: |
Code for example Java program in section 37.13.
|
| Code sample: |
37_1 |
| Type: |
code sample |
| Item: |
Code sample 37_1 without caption |
| Keywords: |
Java, applet
|
|