Reputation: 163
Hey I have some simple code that is a game. I want to have an icon I can double click to open this game instead of opening my code and compiling and running it. Is there a simple way to do this? I don't want it to be an executable because I am on a mac. Here is my code.
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);
}
}
Upvotes: 0
Views: 902
Reputation: 8421
You can either do what Tom told you.. or you can create a small sh (shell script) file. Before doing this you will have to have created the jar file or you should have class files. Compiling every time and then running it was not what java was meant to be. If its a simple app then you can export a jar file right from your IDE. If you are using Eclipse, then right click on the project and click on Export and then select Jar file.
To run the java application on a mac.. open up the Apple Script Editor and enter the command to launch your application.. that would be like
java -jar <your jar file path> <main class>
Click on Save as and select Application. This would create a nice file with .app extension that you can drop into your applications folder.
Upvotes: 1
Reputation: 44821
You want to build it into a jar file with your main class referenced in the manifest.
You can try using apache ant to do this: http://ant.apache.org/manual/Tasks/jar.html
Upvotes: 3