1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| public void actionPerformed(ActionEvent e) {
try {
pattern = textField.getText().toLowerCase();
if (wholeWordCheckBox.getState() == true && partWordCheckBox.getState() == true) {
} else {
if (wholeWordCheckBox.getState() == true) {
if (!pattern.equals("")) {
if (fileContent.toLowerCase().contains("\n"+pattern+" ") || fileContent.toLowerCase().contains(" "+pattern+" ")) {
textField.setForeground(Color.green);
position = fileContent.indexOf(pattern);
System.out.println(fileContent.indexOf(pattern));
} else {
textField.setForeground(Color.red);
System.out.println(" It is not present");
}
}
}
else if (partWordCheckBox.getState() == true) {
if (!pattern.equals("")) {
if (fileContent.toLowerCase().contains(pattern)) {
textField.setForeground(Color.green);
position = fileContent.indexOf(pattern);
System.out.println(fileContent.indexOf(pattern));
} else {
textField.setForeground(Color.red);
System.out.println(" It is not present");
}
}
}
}
} catch (NumberFormatException nfe) {
nfe.printStackTrace();
}
}
public String getText() {
return textField.getText();
}
public String getPattern(){
return pattern;
}
public int getPosition(){
return position;
}
public void setText(String text) {
fileContent = text;
} |
Partager