package com.example.spamchecker;import java.io.File;import java.io.FileNotFoundException;import java.util.ArrayList;import java.util.Scanner;import java.util.regex.Matcher;import java.util.regex.Pattern;import javafx.application.Application;import javafx.event.ActionEvent;import javafx.event.EventHandler;import javafx.geometry.Insets;import javafx.scene.Scene;import javafx.scene.control.Button;import javafx.scene.control.Label;import javafx.scene.control.TextArea;import javafx.scene.layout.GridPane;import javafx.stage.Stage;public class SpamScanner extends Application { static TextArea resultField; static ArrayList<String> spamWordsList; @Override public void start(Stage primaryStage) throws Exception { GridPane pane = new GridPane(); Scene scene = new Scene(pane); pane.setPadding(new Insets(20)); pane.setHgap(10); pane.setVgap(10); TextArea inputText = new TextArea(); inputText.setWrapText(true); pane.add(inputText, 0, 1, 3, 3); Button checkButton = new Button("Scan message"); pane.add(checkButton, 0, 4); Label label1 = new Label("Score: "); pane.add(label1, 1, 4); Label label2 = new Label("Spam likelihood: "); pane.add(label2, 2, 4); Button clearButton = new Button("Clear"); pane.add(clearButton, 3, 4); resultField = new TextArea(); resultField.setPrefRowCount(3); resultField.setEditable(false); pane.add(resultField, 0, 5); primaryStage.setTitle("Spam Scanner"); primaryStage.setScene(scene); primaryStage.show(); readTextFile(); checkButton.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { String text = inputText.getText(); if (text == null || text.equals("")) { resultField.setText("Input can't be blank!"); } else { String regex = "^[A-Za-z\s]+$"; Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(text); if (matcher.find()) { int spamScore = 0; text = text.toLowerCase(); if (spamWordsList != null) { for (String phrase : spamWordsList) { if (text.contains(phrase.toLowerCase())) { spamScore++; } } if (spamScore == 0) { resultField.setText("Spam score is 0n" + "The input doesn't look like a spam messagen"); } else { if (spamScore > 0 && spamScore <= 3) { resultField.setText("Spam score is " + spamScore + "nThe message has some spammy words which can be avoided"); } else if (spamScore > 3 && spamScore <= 6) { resultField.setText("Spam score is " + spamScore + "nThe message looks more like a spam"); } else { resultField.setText("Spam score is " + spamScore + "nThis is definitely SPAM!!!"); } } } } else { resultField.setText("Invalid characters found! Type alphabets and spaces only"); } } } }); clearButton.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { inputText.setText(""); resultField.setText(""); } }); } static void readTextFile() { try { File file = new File("C:\Users\singh\OneDrive\Documents\spam.txt"); Scanner scanner = new Scanner(file); spamWordsList = new ArrayList<>(); while (scanner.hasNext()) { spamWordsList.add(scanner.nextLine()); } resultField.setText("spam.txt file read successfully! Type the mail and press check button"); } catch (FileNotFoundException ex) { resultField.setText("spam.txt file not found"); } } public static void main(String[] args) { launch(args); }}