// Obtain the valid email address of the webpage in Java --- by 77
Import java. AWT .*;
Import java. AWT. event .*;
Import java.net .*;
Import java. Io .*;
Import java. util .*;
Import java. util. RegEx. matcher;
Import java. util. RegEx. pattern;
Public class solo7 {
Public static void main (string ARGs []) {
New win ();
}
}
Class win extends frame implements actionlistener, runnable {
Button button;
URL;
Textfield text;
Textarea area;
Byte B [] = new byte [118];
Thread thread;
Win (){
TEXT = new textfield (20 );
Area = new textarea (12, 12 );
Button = new button ("OK ");
Button. addactionlistener (this );
Thread = new thread (this );
Panel P = new Panel ();
P. Add (new label ("Enter URL :"));
P. Add (text );
P. Add (button );
Add (area, borderlayout. center );
Add (p, borderlayout. North );
Setbounds (60, 60, 360,300 );
Setvisible (true );
Validate ();
Addwindowlistener (New windowadapter (){
Public void windowclosing (windowevent e ){
System. Exit (0 );
}
});
}
Public void actionreceivmed (actionevent e ){
If (! (Thread. isalive ()))
Thread = new thread (this );
Try {
Thread. Start ();
}
Catch (exception ee ){
Text. settext ("reading" + URL );
}
}
Private Boolean isnameadressformat (string email ){
Boolean isexist = false;
Pattern P = pattern. Compile ("// W {1, }@// W {1 ,}
/56 // W {1 ,}");
Matcher M = P. matcher (email );
Boolean B = M. Matches ();
If (B ){
Isexist = true;
} Else {
Isexist = false;
}
Return isexist;
}
Public void run (){
Try {
Int n =-1;
Area. settext (null );
Url = new URL (text. gettext (). Trim ());
Inputstream in = URL. openstream ();
String S = "";
While (n = in. Read (B ))! =-1 ){
S + = new string (B, 0, N );
}
Stringtokenizer Fenxi = new stringtokenizer (S ,"
: = ,?!. : <> & () [] {} // "/'");
Int I = Fenxi. counttokens ();
Area. append ("Total" + I + "strings, such as valid email addresses
Below :");
While (Fenxi. hasmoretokens ()){
String STR = Fenxi. nexttoken ();
If (isnameadressformat (STR ))
Area. append (STR + "");
}
}
Catch (malformedurlexception E1 ){
Text. settext ("" + E1 );
Return;
}
Catch (ioexception E1 ){
Text. settext ("" + E1 );
Return;
}
}
}