[Solved] Replace dot with a space and reverse using java swing [closed]


Your code is not proper, its full with bad practice. After a lot of effort I understood your problem. I am just giving the solution of the specific problem, but try to follow the comments given to your question for better understanding of the uses of Java swing components.

Solution:

change this portion of your code

public void itemStateChanged(ItemEvent ie) {
            if(ViewSpace.getState()){
                tx.setText(previous.replace(" ","."));
        }
            else
                tx.setText(str);
        }

with this one

public void itemStateChanged(ItemEvent ie) {
                if(ViewSpace.getState()){
                    tx.setText(tx.getText().replace(" ","."));

            }
                else
                {
                    String last = tx.getText().substring(tx.getText().length()-1, tx.getText().length());
                    String rest = tx.getText().substring(0, tx.getText().length()-1);
                    if(!last.equals("."))
                    tx.setText(tx.getText().replace("."," "));
                    else
                        {
                        rest=rest.replace("."," ");
                        tx.setText(rest+".");

                        }
                }

4

solved Replace dot with a space and reverse using java swing [closed]