无法创建Runnable JAR文件(Eclipse)

时间:2016-01-04 19:17:19

标签: java eclipse jar export

我在日食中做了一个小游戏,但我无法导出它。每当我尝试这样做时,都没有启动配置,经过一段时间的玩弄,我发现了如何创建一个,但现在我得到了错误

“JAR导出已完成警告。有关其他信息,请参阅详细信息。   使用编译警告导出:space / src / space / main.java   罐子出口完成了问题。详细信息请参阅其他信息。     无法从给定的启动配置中找到主要方法。“

我目前正在使用两个类文件。我读过它可能是因为它不是GUI,但它不使用控制台并在窗口中显示,所以我可能只是感到困惑。     包空间;

import java.awt.Graphics;
public class main extends gameloop{

public void init(){
    setSize(1280,720);  
    Thread th = new Thread(this);
    th.start();
    offscreen = createImage(1280,720);
    d = offscreen.getGraphics();
    addKeyListener(this);
}
public void paint(Graphics g){
d.clearRect(0,0,1280,720);
d.drawImage(voidspace,0,0, this);
d.drawImage(wall,50,0,this);
d.drawImage(floor,100,0,this);



int[][] map=
    {
            {20,27,28,27,28,22},
            {24,11,14,14,17,31},
            {25,12,15,15,18,31},
            {26,13,16,16,19,31},
            {21,29,30,29,30,23}

    };
int rows = 5;
int cols = 6;
int i, j;

for (i = 0; i < rows; i++) {
  for (j = 0; j < cols; j++) {

    if(txtremode == 1){
        if(map[i][j] == 10){
        d.drawImage(voidspace,i*50,j*50,this);
    }
        if(map[i][j] == 11){
        d.drawImage(floor,i*50,j*50,this);
    }
        if(map[i][j] == 12){
            d.drawImage(floor,i*50,j*50,this);
        }
        if(map[i][j] == 13){
            d.drawImage(floor,i*50,j*50,this);
        }
        if(map[i][j] == 14){
            d.drawImage(floor,i*50,j*50,this);
        }
        if(map[i][j] == 15){
            d.drawImage(floor,i*50,j*50,this);
        }
        if(map[i][j] == 16){
            d.drawImage(floor,i*50,j*50,this);
        }
        if(map[i][j] == 17){
            d.drawImage(floor,i*50,j*50,this);
        }
        if(map[i][j] == 18){
            d.drawImage(floor,i*50,j*50,this);
        }
        if(map[i][j] == 19){
            d.drawImage(floor,i*50,j*50,this);
        }
        //corners
        if(map[i][j] == 20){
        d.drawImage(wall,i*50,j*50,this);

    }
        if(map[i][j] == 21){
            d.drawImage(wall,i*50,j*50,this);

        }
        if(map[i][j] == 22){
            d.drawImage(wall,i*50,j*50,this);

        }
        if(map[i][j] == 23){
            d.drawImage(wall,i*50,j*50,this);

        }

        //walls
        if(map[i][j] == 24){
            d.drawImage(wall,i*50,j*50,this);

        }
        if(map[i][j] == 25){
            d.drawImage(wall,i*50,j*50,this);

        }
        if(map[i][j] == 26){
            d.drawImage(wall,i*50,j*50,this);

        }
        if(map[i][j] == 27){
            d.drawImage(wall,i*50,j*50,this);

        }
        if(map[i][j] == 28){
            d.drawImage(wall,i*50,j*50,this);

        }
        if(map[i][j] == 29){
            d.drawImage(wall,i*50,j*50,this);

        }
        if(map[i][j] == 30){
            d.drawImage(wall,i*50,j*50,this);

        }
        if(map[i][j] == 31){
            d.drawImage(wall,i*50,j*50,this);

        }


    }



    //easteregg
    if(txtremode == 112109100){

        if(map[i][j] == 10){
        d.drawImage(voidspace,i*50,j*50,this);
        }

        //pmd-based floors(1-9)
        if(map[i][j] == 11){
        d.drawImage(pmdtlf,i*50,j*50,this);
        }
        if(map[i][j] == 12){
            d.drawImage(pmdtmf,i*50,j*50,this);
            }
        if(map[i][j] == 13){
            d.drawImage(pmdtrf,i*50,j*50,this);
            }
        if(map[i][j] == 14){
            d.drawImage(pmdmlf,i*50,j*50,this);
            }
        if(map[i][j] == 15){
            d.drawImage(pmdflr_base,i*50,j*50,this);
            }
        if(map[i][j] == 16){
            d.drawImage(pmdmrf,i*50,j*50,this);
            }
        if(map[i][j] == 17){
            d.drawImage(pmdblf,i*50,j*50,this);
            }
        if(map[i][j] == 18){
            d.drawImage(pmdbmf,i*50,j*50,this);
            }
        if(map[i][j] == 19){
            d.drawImage(pmdbrf,i*50,j*50,this);
            }

        //pmd-based corners
        if(map[i][j] == 20){
        d.drawImage(pmdtlc,i*50,j*50,this);
        }
        if(map[i][j] == 21){
            d.drawImage(pmdtrc,i*50,j*50,this);
            }
        if(map[i][j] == 22){
            d.drawImage(pmdblc,i*50,j*50,this);
            }
        if(map[i][j] == 23){
            d.drawImage(pmdbrc,i*50,j*50,this);
            }

        //pmd-based walls
        if(map[i][j] == 24){
            d.drawImage(pmdtw1,i*50,j*50,this);
            }
        if(map[i][j] == 25){
            d.drawImage(pmdtw2,i*50,j*50,this);
            }
        if(map[i][j] == 26){
            d.drawImage(pmdtw3,i*50,j*50,this);
            }
        if(map[i][j] == 27){
            d.drawImage(pmdlw1,i*50,j*50,this);
            }
        if(map[i][j] == 28){
            d.drawImage(pmdlw2,i*50,j*50,this);
            }
        if(map[i][j] == 29){
            d.drawImage(pmdrw1,i*50,j*50,this);
            }
        if(map[i][j] == 30){
            d.drawImage(pmdrw2,i*50,j*50,this);
        }
        if(map[i][j] == 31){
            d.drawImage(pmdbw1,i*50,j*50,this);
            }

    }
  }
}


g.drawImage(offscreen,0,0,this );

}
public void update(Graphics g){
paint (g);
}
}

接下来主要是一个循环,但我还没有实现。

package space;

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

@SuppressWarnings("serial")
public class gameloop extends Applet implements Runnable, KeyListener{

    public int x,y,windowx,windowy,txtremode;
    public Image offscreen; 
    public Graphics d;
    public boolean up, down, left, right;
    public BufferedImage closed_door,floor,open_door,voidspace,wall; //default
    public BufferedImage pmdtiles,pmdtlc,pmdtrc,pmdblc,pmdbrc; //pmd-based wall corners
    public BufferedImage pmdtw1,pmdtw2,pmdtw3,pmdlw1,pmdlw2,pmdrw1,pmdrw2,pmdbw1;//pmd-based walls (w/ varients)
    public BufferedImage pmdtlf,pmdtmf,pmdtrf,pmdmlf,pmdflr_base,pmdmrf,pmdblf,pmdbmf,pmdbrf; //pmd-based floor(1-9)
    public int counter;
    public double counter2 = 0;
    public String score2 = "";
    public void run() {
        try {
        wall = ImageIO.read(new File("wall.png"));
        floor = ImageIO.read(new File("floor.png"));
        closed_door = ImageIO.read(new File("closed_door.png"));
        open_door = ImageIO.read(new File("open_door.png"));
        voidspace = ImageIO.read(new File("void.png"));
        pmdtiles = ImageIO.read(new File("pmdtiles.png"));

        //pmd-based wall corners
        pmdtlc = pmdtiles.getSubimage(5, 5, 50, 50);
        pmdtrc = pmdtiles.getSubimage(225, 5, 50, 50);
        pmdblc = pmdtiles.getSubimage(5, 170, 50, 50);
        pmdbrc = pmdtiles.getSubimage(225, 170, 50, 50);

        //pmd-based walls(w/varients)
        pmdtw1 = pmdtiles.getSubimage(60, 5, 50, 50);
        pmdtw2 = pmdtiles.getSubimage(115, 5, 50, 50);
        pmdtw3 = pmdtiles.getSubimage(170, 5, 50, 50);
        pmdlw1 = pmdtiles.getSubimage(5, 60, 50, 50);
        pmdlw2 = pmdtiles.getSubimage(5, 115, 50, 50);
        pmdrw1 = pmdtiles.getSubimage(225, 60, 50, 50);
        pmdrw2 = pmdtiles.getSubimage(225, 115, 50, 50);
        pmdbw1 = pmdtiles.getSubimage(170, 170, 50, 50);


        //pmd-based floors(1-9)

        pmdtlf = pmdtiles.getSubimage(289, 5, 50, 50);
        pmdtmf = pmdtiles.getSubimage(344, 5, 50, 50);
        pmdtrf = pmdtiles.getSubimage(399, 5, 50, 50);
        pmdmlf = pmdtiles.getSubimage(289, 60, 50, 50);
        pmdflr_base = pmdtiles.getSubimage(60, 60, 50, 50);
        pmdmrf = pmdtiles.getSubimage(399, 60, 50, 50);
        pmdblf = pmdtiles.getSubimage(289, 115, 50, 50);
        pmdbmf = pmdtiles.getSubimage(344, 115, 50, 50);
        pmdbrf = pmdtiles.getSubimage(399, 115, 50, 50);


        txtremode = 112109100;





    }

        catch (IOException el) {
        el.printStackTrace();
    }
        while(true){


            repaint();
        try {
            Thread.sleep(20);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        }
    }

    public void keyPressed(KeyEvent e) {
        if(e.getKeyCode() ==37){
            left = true;
        }
        if(e.getKeyCode() ==38){
            up = true;
        }
        if(e.getKeyCode() ==39){
            right = true;
        }
        if(e.getKeyCode() ==40){
            down = true;
        }
         }
    public void keyReleased(KeyEvent e) {
        if(e.getKeyCode() == 37){
            left = false;
        }
        if(e.getKeyCode() == 38){
            up = false;
            counter2 = 4;
        }
        if(e.getKeyCode() == 39){
            right = false;
        }
        if(e.getKeyCode() == 40){
            down = false;

    }
}
public void keyTyped(KeyEvent e) {
}
}

1 个答案:

答案 0 :(得分:0)

在您的情况下,您在使用applet时不需要 main 方法。

您可以尝试执行以下操作:

  1. gameloop 中删除包“space”或将其添加到 main
  2. 编译代码

    javac gameloop.java javac -cp。 main.java

  3. 将代码作为applet运行

    appletviewer main.class

  4. 确保所有文件到位(wall.png,floor.png等)

  5. 如果您希望能够通过 java 命令运行 main.java ,则需要添加 public static void main(String [ ] arg)进入它并确保创建 main 对象并调用它的 init 方法。