有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java JOptionPane将我的代码转化为实际的游戏

嘿,我有一些简单的游戏代码。我想有一个图标,我可以双击打开这个游戏,而不是打开我的代码,编译和运行它。有没有简单的方法可以做到这一点?我不想让它成为可执行文件,因为我在mac电脑上。这是我的密码

import javax.swing.*;
import java.awt.*;
public class test{
    public static void main(String[] args){


//Custom button text
Object[] options = {"Right",
                    "Left"};
int n = JOptionPane.showOptionDialog(null,
    "Which way would you like to go?",
    "Adventure Game",
    JOptionPane.YES_NO_CANCEL_OPTION,
    JOptionPane.QUESTION_MESSAGE,
    null,
    options,
    options[0]);

     if(n == JOptionPane.YES_OPTION)
        JOptionPane.showOptionDialog(null,
        "You went the wrong way!",
        "Adventure Game",
        JOptionPane.YES_NO_CANCEL_OPTION,
        JOptionPane.QUESTION_MESSAGE,
        null,
        options,
        options[0]);
    else
        JOptionPane.showOptionDialog(null,
    "You went left!",
    "Adventure Game",
    JOptionPane.YES_NO_CANCEL_OPTION,
    JOptionPane.QUESTION_MESSAGE,
    null,
    options,
    options[0]);




     System.exit(0);
    }
}

共 (2) 个答案

  1. # 1 楼答案

    你要么照汤姆说的做。。也可以创建一个小的sh(shell脚本)文件。在这样做之前,您必须创建jar文件,或者应该有类文件。每次编译然后运行它并不是java的本意。如果它是一个简单的应用程序,那么你可以直接从IDE导出jar文件。如果您使用的是Eclipse,那么右键单击项目并单击导出,然后选择Jar文件

    在mac上运行java应用程序。。打开Apple脚本编辑器,输入启动应用程序的命令。。那就像

    java -jar <your jar file path> <main class>
    

    单击另存为并选择应用程序。这将创建一个很好的文件。可以放入应用程序文件夹的应用程序扩展