Cześć,
Mam w swoim programie element JTextArea i moim zadaniem jest sprawdzanie, czy w wpisanym tekście nie ma żadnych niecenzuralnych słów. Jeśli są - należy zastąpić je gwiazdkami. Niestety to co napisałem, nie bardzo się nadaje -> działa bardzo wolno i się wiesza. Jakby mógł mi ktoś podpowiedzieć, czego dokładnie użyć, aby móc na bieżąco modyfikować zawartość JTextArea byłbym bardzo wdzięczny.
Pozdrawiam

 class TextAreaListener implements DocumentListener
    {

        public void removeUpdate(DocumentEvent e)
        {
            Runnable r=new Runnable()
            {

                public void run()
                {
                   textArea.setText(checkContents());
                }

            };
            SwingUtilities.invokeLater(r);


        }
        public void insertUpdate(DocumentEvent e)
        {
            Runnable r=new Runnable()
            {
                public void run()
                {
                    textArea.setText(checkContents());
                }

            };
            SwingUtilities.invokeLater(r);

        }
        public void changedUpdate(DocumentEvent e) {}

    }
    public MainJFrame() {
        initComponents();
        textArea.getDocument().addDocumentListener(new TextAreaListener());
            
    }

    private String checkContents()
    {
        String words[]=new String[]{"dupa","gówno","chuj"};

        String text=textArea.getText();
        text=text.toLowerCase();


        for(int i=0;i<words.length;i++)
        {
            String replacement="";
            int size=words[i].length();
            replacement+=words[i].charAt(0);

            for(int j=0;j<size-2;j++)
            {
                replacement+="*";
            }

            replacement+=words[i].charAt(size-1);
            text.replace(words[i], replacement);
        }

        return text;
        
         
    }