java游戏逻辑
我建立在使用Joption的想法之上,如果有人能帮助我,我将不胜感激
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
public class TestOptionPane {
public static void main(String[] args) {
ImageIcon icon = new ImageIcon(
TestOptionPane.class.getResource("/resources/安卓.jpg"));
String answer = (String)JOptionPane.showInputDialog(
null, "Spell the Image", "Spell the Image",
JOptionPane.QUESTION_MESSAGE, icon, null, null);
if (answer.equals("Android")) {
System.out.println("Yayyy");
System.exit(0);
}
}
# 1 楼答案
因为您的程序只是一个控制台程序,而且您没有Swing方面的经验,所以我将为您提供一个在
JOptionPane
中显示图像的简单解决方案你能做的就是让你
Word
去ImageIcon
您可以在
WordRepository
类中创建Word
文件结构应该是什么样子的
然后,当你想在程序中显示它时,你可以用
JOptionPane
这样的方式来显示它有关我传递给它的参数的更多细节,请参见JOptionPane API
您可以将其用作一个简单的测试程序。只需正确更改图像的路径,并更改希望输入相等的字符串
# 2 楼答案
这取决于你工作的平台。例如,如果您正在为
Android
工作,则必须更改Word
构造函数并添加Bitmap
类型。比如例如:
但最后,您可以更改
Bitmap
类型以获得所需的任何内容,然后将其添加到Map
或在您的情况下添加到LinkedList
编辑:我在你的评论中读到你正在做
GUI
。您必须使用String type
,并将path
添加到构造函数的映像中