I'm doing some error checking in two JTextFields. I'll label them jtext1 and jtext2.
Right now my GUI looks like this:
Enter number 1: [      ] // jtext1
Enter number 2: [      ] // jtext2
Convert         [ answer ]
I want to be able to check for multiple conditions and display an error message. For example, if the user enters nothing for both text fields, and hits convert the following should appear:
Enter number 1: [  Nothing entered    ] // jtext1
Enter number 2: [  Nothing entered    ] // jtext2
Convert         [ answer ]
And, if you use the mouse to click on jtext1 I want it to clear the message so the user can enter a number. If they click on jtext2 the same thing should also happen.
So for example if I were to click on jtext2 the following should appear:
Enter number 1: [  Nothing entered    ] // jtext1
Enter number 2: [        ]              // jtext2
Convert         [ answer ]
The problem is, with this piece of code:
if(!jtext1.isvalid()) {
    jtext1.setText("Nothing entered");
    jtext1.addMouseListener(new MouseAdapter(){
        @Override
        public void mouseClicked(MouseEvent e) {
            jtext1.setText("");
        }
    });
}
if(!jtext2.isvalid()) {
    jtext2.setText("Nothing entered");
    jtext2.addMouseListener(new MouseAdapter(){
        @Override
        public void mouseClicked(MouseEvent e) {
            jtext2.setText("");
        }
    });
}
Only jtext1 will work. This sort of makes sense to me, because I don't think I can keep overriding the same function, but how would I go around the issue?
 
     
     
    