简体   繁体   English

错误消息无法正确显示

[英]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 因此,在Problem.java中,我将其设置为

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 : 当我不放置像这样的图块时,会出现错误消息:“未放置图块”,就像代码中的内容一样,但最终却像这样:

在此处输入图片说明

What's wrong with my code anyway? 我的代码到底有什么问题?

You either need to pass p.message to the dialog or override Problem's toString() method and return message there. 您要么需要将p.message传递给对话框,要么重写Problem的toString()方法并在此处返回message What you're seeing is the output of standard toString() , ie class name + instance id. 您将看到标准toString()的输出,即类名+实例ID。

Btw, you posted a lot of irrelevant code, which might make a lot of people want to either close the question or prevent them from trying to answer. 顺便说一句,您发布了许多不相关的代码,这可能使很多人想要关闭问题或阻止他们尝试回答。 When asking questions you should try and boil it down to the relevant parts, which in your case would be how you display the dialog and what the parameters look like. 提出问题时,应尝试将其简化为相关部分,在您的情况下,这将是如何显示对话框以及参数的外观。 For more information, have a look here: https://stackoverflow.com/help/how-to-ask 有关更多信息,请在此处查看: https : //stackoverflow.com/help/how-to-ask

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM