javamessage

Error message doesn't display correctly


I'm trying to make dialog that will display an error message whenever I make wrong move in my scrabble game. So in Problem.java, I make it like this

class Problem
{
   Problem(String s)
  {
        message = s;
  }
}

So I write code to display the warning like this :

    void displayProblem(Problem p)
    {

        JOptionPane.showMessageDialog(this,p, "WARNING!",JOptionPane.WARNING_MESSAGE);
    }

I expect error message when I don't put tile something like this : "no tiles placed" just like what's in the code but it ended up like this :

enter image description here

What's wrong with my code anyway?


Solution

  • You either need to pass p.message to the dialog or override Problem's toString() method and return message there. What you're seeing is the output of standard toString(), i.e. class name + instance id.