See More

package elearning; import java.awt.Color; import java.io.File; import java.io.FileNotFoundException; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.JEditorPane; import javax.swing.JTextArea; import javax.swing.JTextPane; import javax.swing.SwingUtilities; import javax.swing.text.Document; import javax.swing.text.Style; import javax.swing.text.StyledDocument; public class Help { private final Pattern keywordPattern=Pattern.compile("abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|native|new|packages|private|protected|public|return|short|static|strictfp|super|switch|synchronized|this|throw|throws|transient|try|void|volatile|while"); private final Pattern commentPattern=Pattern.compile("\\/\\/.*"); //private final Pattern commentPattern=Pattern.compile("\\/\\/.*//\n"); // private final Pattern literalPattern=Pattern.compile("\\([a-zA-z]\\)"); //private final Pattern literalPattern=Pattern.compile("(\\p{Punct}| )*"+"test"+ "(\\p{Punct}| )*"); private final Pattern literalPattern=Pattern.compile("\"[a-z0-9]*\""); private String []theWords={"abstract","assert","boolean","break","byte","case","catch","char","class", "const","continue","default","do","double","else","enum","extends","final","finally","float", "for","goto","if","implements","import","instanceof","int","interface","long","native","new", "packages","private","protected","public","return","short","static","strictfp","super","switch", "synchronized","this","throw","throws","transient","try","void","volatile","while"}; private Pattern [] holder=new Pattern[reservedWords.length]; //private static Matcher matcher; public Help(){} public Pattern getPattern(){ return this.keywordPattern; } public Pattern commentPattern(){ return this.commentPattern; } public Pattern literalPattern(){ return this.literalPattern; } public HashMap hashJavaWords(String text){ Scanner scan=new Scanner(text); HashMap temp=new HashMap(); List tempList=Arrays.asList(theWords); while(scan.hasNext()){ String w=scan.next(); Matcher matcher=getPattern().matcher(w); if(matcher.matches()) for (int i=0; i