如何使.jar文件可单击

时间:2016-05-12 22:10:32

标签: java jar

我已经从这段代码中创建了一个.jar文件,我希望能够点击它然后运行它。需要做什么?

import javax.swing.JOptionPane;

public class HeadsVsTails {
public static void main(String[] args){

    int value = 0;
    int gameToken = 20;
    int win = 0;
    int lose = 0;

    while(gameToken > 0) {

        gameToken = --gameToken;

        int headsOrTails = (int)(Math.random() * 10); 

        if(headsOrTails >= 5)
            value = 1;
        else 
            value = 0;

        String userInput = JOptionPane.showInputDialog(null , "enter heads or tails for your guess");
        char lastChar = userInput.charAt(3);

        if(value == 1 && lastChar == 'd') {
            // a win

            win = ++win;

            JOptionPane.showMessageDialog(null, "you guessed right\n" + "  " + "wins: " + win 
            + " \n" + " loss's:" + lose + "\n" + "tokens left:" + gameToken);
            } 
        else if ( value == 1 && lastChar == 'l'){
            //a lose

            lose = ++ lose;

            JOptionPane.showMessageDialog(null, "oh im sorry thats a not right\n" + " " + "wins:" + win 
            + "\n" + "loss's:" + lose + "\n" + "tokens left:" + gameToken);

        }
        else if (value == 0 && lastChar == 'd'){
            //a lose

            lose = ++ lose;

            JOptionPane.showMessageDialog(null, "oh im sorry thats a not right\n" + " " + "wins:" + win 
            + "\n" + "loss's:" + lose + "\n" + "tokens left:" + gameToken);

        }
        else if (value == 0 && lastChar == 'l'){
            // a win

                            win = ++win;

            JOptionPane.showMessageDialog(null, "you guessed right\n" + "  " + "wins: " + win 
            + " \n" + " loss's:" + lose + "\n" + "tokens left:" + gameToken);
            }
        }

        }
    }

我知道这段代码可能看起来很乱,但它所做的就是让用户进行20次更改以猜测硬币落在哪一侧,然后跟踪它们的效果。我可以在终端运行它,它可以工作,但我想在我的桌面上的文件,我可以点击。需要做什么?

提前谢谢

0 个答案:

没有答案