java程序在ide中运行良好,但不能作为导出文件

lawou6xi  于 2021-06-30  发布在  Java
关注(0)|答案(2)|浏览(244)

这个问题在这里已经有答案了

我可以通过cmd运行.jar文件,但不能双击它们(7个答案)
上个月关门了。
我的扫雷器项目在ide中工作得很好,但是当我在eclipse中将is导出为“runnable jar file”并随后执行它时,它就不工作了。我的舱单.mf
我还尝试通过cmd导航到那里,并使用javac minesweeper.jar。
控制台说它找不到命令“javac”。
如果我把cd放入我的文件夹,只做java minesweeper.jar,它会说:“找不到或加载mainclass minesweeper.jar”
这是主方法所在的代码:

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;

import javax.swing.JSpinner;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import javax.swing.JLabel;
import java.awt.Insets;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Font;
import javax.swing.ImageIcon;

@SuppressWarnings("serial")
public class Anzeigen extends JFrame {

    private JPanel contentPane;

     int spaltenAnzahl,bombenAnzahl,reihenAnzahl;

     Logik logik;

    public Anzeigen() {
        logik = new Logik();
        reihenAnzahl = 2;
        spaltenAnzahl = 2;
        bombenAnzahl = 1;
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(800, 300, 700, 500);

        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        GridBagLayout gbl_contentPane = new GridBagLayout();
        gbl_contentPane.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
        gbl_contentPane.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
        gbl_contentPane.columnWeights = new double[]{0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, Double.MIN_VALUE};
        gbl_contentPane.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
        contentPane.setLayout(gbl_contentPane);

        JLabel lblReihenanzahl = new JLabel("ReihenAnzahl");
        lblReihenanzahl.setFont(new Font("Tahoma", Font.BOLD, 15));
        GridBagConstraints gbc_lblReihenanzahl = new GridBagConstraints();
        gbc_lblReihenanzahl.insets = new Insets(0, 0, 5, 5);
        gbc_lblReihenanzahl.gridx = 4;
        gbc_lblReihenanzahl.gridy = 0;
        contentPane.add(lblReihenanzahl, gbc_lblReihenanzahl);

        JLabel lblSpaltenanzahl = new JLabel("SpaltenAnzahl");
        lblSpaltenanzahl.setFont(new Font("Tahoma", Font.BOLD, 15));
        GridBagConstraints gbc_lblSpaltenanzahl = new GridBagConstraints();
        gbc_lblSpaltenanzahl.insets = new Insets(0, 0, 5, 5);
        gbc_lblSpaltenanzahl.gridx = 7;
        gbc_lblSpaltenanzahl.gridy = 0;
        contentPane.add(lblSpaltenanzahl, gbc_lblSpaltenanzahl);

        JLabel lblAnzahlminen = new JLabel("AnzahlMinen");
        lblAnzahlminen.setFont(new Font("Tahoma", Font.BOLD, 15));
        GridBagConstraints gbc_lblAnzahlminen = new GridBagConstraints();
        gbc_lblAnzahlminen.insets = new Insets(0, 0, 5, 0);
        gbc_lblAnzahlminen.gridx = 9;
        gbc_lblAnzahlminen.gridy = 0;
        contentPane.add(lblAnzahlminen, gbc_lblAnzahlminen);

        JSpinner spinner_1 = new JSpinner();
        spinner_1.setFont(new Font("Tahoma", Font.PLAIN, 20));
        GridBagConstraints gbc_spinner_1 = new GridBagConstraints();
        gbc_spinner_1.gridheight = 4;
        gbc_spinner_1.fill = GridBagConstraints.BOTH;
        gbc_spinner_1.insets = new Insets(0, 0, 5, 5);
        gbc_spinner_1.gridx = 7;
        gbc_spinner_1.gridy = 1;
        contentPane.add(spinner_1, gbc_spinner_1);

        JSpinner spinner_2 = new JSpinner();
        spinner_2.setFont(new Font("Tahoma", Font.PLAIN, 20));
        GridBagConstraints gbc_spinner_2 = new GridBagConstraints();
        gbc_spinner_2.fill = GridBagConstraints.BOTH;
        gbc_spinner_2.gridheight = 4;
        gbc_spinner_2.insets = new Insets(0, 0, 5, 0);
        gbc_spinner_2.gridx = 9;
        gbc_spinner_2.gridy = 1;
        contentPane.add(spinner_2, gbc_spinner_2);

        JLabel label = new JLabel("");
        label.setIcon(new ImageIcon(Anzeigen.class.getResource("/javax/swing/plaf/metal/icons/Warn.gif")));
        GridBagConstraints gbc_label = new GridBagConstraints();
        gbc_label.fill = GridBagConstraints.BOTH;
        gbc_label.insets = new Insets(0, 0, 0, 5);
        gbc_label.gridx = 6;
        gbc_label.gridy = 9;
        label.setVisible(false);

        JSpinner spinner = new JSpinner();
        spinner.setFont(new Font("Tahoma", Font.PLAIN, 20));
        GridBagConstraints gbc_spinner = new GridBagConstraints();
        gbc_spinner.fill = GridBagConstraints.BOTH;
        gbc_spinner.gridheight = 4;
        gbc_spinner.insets = new Insets(0, 0, 5, 5);
        gbc_spinner.gridx = 4;
        gbc_spinner.gridy = 1;
        contentPane.add(spinner, gbc_spinner);

        spinner.setValue(2);
        JLabel lblNewLabel = new JLabel("");
        lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 15));
        GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
        gbc_lblNewLabel.fill = GridBagConstraints.BOTH;
        gbc_lblNewLabel.insets = new Insets(0, 0, 0, 5);
        gbc_lblNewLabel.gridx = 7;
        gbc_lblNewLabel.gridy = 9;
        lblNewLabel.setVisible(false);
        contentPane.add(lblNewLabel, gbc_lblNewLabel);
        spinner_1.setValue(2);
        spinner_2.setValue(1);
        JButton btnStart = new JButton("Start");
        btnStart.setFont(new Font("Tahoma", Font.PLAIN, 20));
        btnStart.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent arg0) {
                lblNewLabel.setVisible(false);
                spaltenAnzahl = (int) spinner_1.getValue();
                reihenAnzahl = (int) spinner.getValue();
                bombenAnzahl = (int) spinner_2.getValue();
                System.out.println("SpaltenAnzahl: "+spaltenAnzahl);
                System.out.println("ReihenAnzahl: "+reihenAnzahl);
                System.out.println("BombenAnzahl: "+bombenAnzahl);
                if(bombenAnzahl > spaltenAnzahl * reihenAnzahl) {
                    label.setVisible(true);
                    lblNewLabel.setVisible(true);
                    lblNewLabel.setText("Mehr Minen oder mehr Reihen/Spalten");
                }   
                else if(reihenAnzahl * spaltenAnzahl >= 2500) {
                    lblNewLabel.setText("Zu Groß!");
                    lblNewLabel.setVisible(true);
                }
                else {

                logik.inizialisieren(reihenAnzahl,spaltenAnzahl,bombenAnzahl);
                setVisible(false);
                }
            }
        });

        JLabel lblDirektStarten = new JLabel("Direkt Starten:");
        lblDirektStarten.setFont(new Font("Tahoma", Font.BOLD, 15));
        GridBagConstraints gbc_lblDirektStarten = new GridBagConstraints();
        gbc_lblDirektStarten.insets = new Insets(0, 0, 5, 5);
        gbc_lblDirektStarten.gridx = 1;
        gbc_lblDirektStarten.gridy = 7;
        contentPane.add(lblDirektStarten, gbc_lblDirektStarten);
        GridBagConstraints gbc_btnStart = new GridBagConstraints();
        gbc_btnStart.insets = new Insets(0, 0, 5, 0);
        gbc_btnStart.gridx = 9;
        gbc_btnStart.gridy = 7;
        contentPane.add(btnStart, gbc_btnStart);

        JButton btnNewButton = new JButton("Einfach");
        btnNewButton.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                logik.inizialisieren(9, 9, 10);
                setVisible(false);
            }
        });
        GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
        gbc_btnNewButton.fill = GridBagConstraints.VERTICAL;
        gbc_btnNewButton.insets = new Insets(0, 0, 5, 5);
        gbc_btnNewButton.gridx = 0;
        gbc_btnNewButton.gridy = 8;
        contentPane.add(btnNewButton, gbc_btnNewButton);

        JButton btnNewButton_1 = new JButton("Mittel");
        btnNewButton_1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                setVisible(false);
                logik.inizialisieren(16, 16, 40);
            }
        });
        GridBagConstraints gbc_btnNewButton_1 = new GridBagConstraints();
        gbc_btnNewButton_1.fill = GridBagConstraints.VERTICAL;
        gbc_btnNewButton_1.insets = new Insets(0, 0, 5, 5);
        gbc_btnNewButton_1.gridx = 1;
        gbc_btnNewButton_1.gridy = 8;
        contentPane.add(btnNewButton_1, gbc_btnNewButton_1);

        JButton btnNewButton_2 = new JButton("Schwer");
        btnNewButton_2.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                setVisible(false);
                logik.inizialisieren(16, 30, 99);
            }
        });
        GridBagConstraints gbc_btnNewButton_2 = new GridBagConstraints();
        gbc_btnNewButton_2.fill = GridBagConstraints.BOTH;
        gbc_btnNewButton_2.insets = new Insets(0, 0, 5, 5);
        gbc_btnNewButton_2.gridx = 2;
        gbc_btnNewButton_2.gridy = 8;
        contentPane.add(btnNewButton_2, gbc_btnNewButton_2);
        contentPane.add(label, gbc_label);

    }

public static void main(String[] args) {

        Anzeigen frame = new Anzeigen();
        frame.setVisible(true);
    }

}
l2osamch

l2osamch1#

我想我得在我的注册处换些东西
我可以通过cmd运行.jar文件,但不能双击它们
当已经有答案的时候再问这个问题。。

up9lanfz

up9lanfz2#

运行可运行jar的方法是 -jar 参数,例如。 java -jar Minesweeper.jar . 否则,它假定您指的是classpath环境变量上的类名,您不应该依赖它。

相关问题