Solution
Download EMailTextFieldTest source code.
HTML Interface to Applet
<APPLET CODEBASE="/applets/magelang/AWT-Training/classes/" CODE="EMailTextFieldTest.class" WIDTH=300 HEIGHT=20 ALIGN=CENTER></APPLET>
Java Code
import java.awt.*;
public class EMailTextFieldTest extends java.applet.Applet {
public void init() {
setLayout(new GridLayout(1,1));
EMailTextField test = new EMailTextField();
add(test);
}
}
/**
* Component containing both a Label and a TextField.
* Used for entering and validating an e-mail address.
*/
class EMailTextField extends LabeledTextField {
public EMailTextField() {
super("E-Mail Address");
}
public void verify() {
String address = text.getText().toUpperCase();
if (!address.endsWith(".COM") &&
!address.endsWith(".EDU") &&
!address.endsWith(".GOV") &&
!address.endsWith(".MIL") &&
!address.endsWith(".ORG") &&
!address.endsWith(".NET") ) {
System.err.println("Invalid internet domain: " +
"Please enter again.");
text.setText("");
}
if (address.indexOf("@") <= 0) {
System.err.println("Invalid user name: " +
"Please enter again.");
text.setText("");
}
}
}
|