package ai1.klientjava;
import java.awt.Container;
import java.awt.BorderLayout;
import java.awt.Panel;
import java.awt.Button;
import java.awt.TextField;
import java.awt.Label;
import java.applet.Applet;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
/**
* A simple applet that writes to System.out when any of the
* four applet methods are called.
*/
public class AppletDemo extends Applet {
/**
* Called when the applet is unloaded. Does nothing but to
* write to System.out.
*/
public void destroy() {
System.out.println("destroy");
}
/**
* Called when the applet is loaded.Writes to System.out
* and displays a simple GUI.
*/
public void init() {
System.out.println("init");
showGUI();
}
/**
* Called when the applet apears on the screen. Does nothing but to
* write to System.out.
*/
public void start() {
System.out.println("start");
}
/**
* Called when the applet is removed from the screen.
* Does nothing but to write to System.out.
*/
public void stop() {
System.out.println("stop");
}
private void showGUI() {
setLayout(new BorderLayout());
final Label infoLabel =
new Label("What's your name?");
infoLabel.setAlignment(Label.CENTER);
add(infoLabel, BorderLayout.CENTER);
Panel getNamePanel = new Panel();
getNamePanel.add(new Label("Enter name here:"));
final TextField nameField = new TextField(20);
getNamePanel.add(nameField);
Button okButton = new Button("OK");
getNamePanel.add(okButton);
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
infoLabel.setText("Your name is " +
nameField.getText());
}
});
add(getNamePanel, BorderLayout.SOUTH);
}
}