我的代码不允许我将图像放入Java代码

时间:2018-09-24 15:55:55

标签: java joptionpane imageicon

我似乎无法修复代码的这一部分,我想要做的就是添加图片,将其放入Java填充中,而我只是不知道发生了什么事情:

ImageIcon al = new ImageIcon("Walmart.jpeg");
JOptionPane.showMessageDialog(null, "Come " + verb + " at WALMART, where you'll receive "
     + adjective + " discounts on all of your favorite brand name "
     + nounplursl + ".", JOptionPane.QUESTION_MESSAGE, al, null);

1 个答案:

答案 0 :(得分:0)

您用来调用showMessageDialog的参数似乎有问题。 删除末尾的null,并在消息后再传递一个字符串。

import pymongo, datetime
from pymongo import MongoClient

client = MongoClient("mongodb://localhost:27017/")

db = client.Experience
collection = db.Reputation

post = {"author": "William",
        "text": "May you help?",
        "date": datetime.datetime.now()}

collection.insert_one(post)

如果仍然看不到图像,请尝试使用getResource。

ImageIcon al = new ImageIcon("Walmart.jpeg");
JOptionPane.showMessageDialog(null, "Come " + verb + " at WALMART, where you'll receive "
     + adjective + " discounts on all of your favorite brand name "
     + nounplursl + ".", "Additional String", JOptionPane.QUESTION_MESSAGE, al);