Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 该程序在eclipse中工作。但是当我导出到可执行文件时,它不会打开JFrame_Java_Swing_Jframe_Embedded Resource_Executable Jar - Fatal编程技术网

Java 该程序在eclipse中工作。但是当我导出到可执行文件时,它不会打开JFrame

Java 该程序在eclipse中工作。但是当我导出到可执行文件时,它不会打开JFrame,java,swing,jframe,embedded-resource,executable-jar,Java,Swing,Jframe,Embedded Resource,Executable Jar,我对这里出了什么问题感到困惑。 我认为JFrame的设置方式有问题。 还有一个生成器类,但我想如果我能让发射器工作,那么生成器就会出现。 非常感谢您的帮助 以下是我的源代码: 主要内容: 发射器: import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.event.ActionEvent; import java.aw

我对这里出了什么问题感到困惑。 我认为JFrame的设置方式有问题。 还有一个生成器类,但我想如果我能让发射器工作,那么生成器就会出现。 非常感谢您的帮助

以下是我的源代码:

主要内容:

发射器:

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.io.File;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

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

    public static Font titleFont;
    public static Font secondFont;
    public static Font generateFont;

    public static int levelHeight;
    public static int levelWidth;
    public static String tileWidth;
    public static String tileHeight;
    public static String destination;
    public static String levelSource;
    public static String tilesetSource;
    public static int tilesetWidth;
    public static int tilesetHeight;

    public static Box box;

    public static JPanel panel;
    public static JPanel panel1;
    public static JPanel panel2;
    public static JPanel panel3;
    public static JPanel panel4;
    public static JPanel panel5;
    public static JPanel panel6;    

    public static JLabel lbltitle;
    public static JLabel lblsecondTitle;
    public static JLabel lblemptyString;
    public static JLabel lblemptyString2;
    public static JLabel lblcomment;
    public static JLabel lblauthor;
    public static JLabel lblTileWidth;
    public static JLabel lblTileHeight;
    public static JLabel lblDestinationFile;
    public static JLabel lblLevelSourceFile;
    public static JLabel lblTileSetSourceFile;
    public static JLabel lblHelp;

    public static JButton generate;

    public static JTextField tfTileWidth;
    public static JTextField tfTileHeight;
    public static JTextField tfDestinationFile;
    public static JTextField tfLevelSourceFile;
    public static JTextField tfTileSetSourceFile;

    public static int dWidth;
    public static int dHeight;
    public static int dTileWidth;
    public static int dTileHeight;
    public static int dTilesetHeight;
    public static int dTilesetWidth;

    public static File fDestination;
    public static File fLevelSource;
    public static File fTileSetSource;

    public static File tsdirectory;
    public static File lmdirectory;

    public static File[] tsList;
    public static File[] lmList;

    public static String[] tslist;
    public static String[] lmlist;

    public static int i;
    public static int checkInputs;

    private JComboBox<String> comboBox;
    private JComboBox<String> comboBox1;    

    public Launcher(){
        super("Dafon's World: Level Generator");
        init();
    }
    public void init(){
        i = 0;
        checkInputs = 0;
        setFrame();
        setDirectories();
        setFonts();
        setJLabels();
        setJButton();
        setJTextFields();
        setJPanels();
        setBox();
        addListeners();

        add(box, BorderLayout.NORTH);
        add(lblauthor, BorderLayout.SOUTH);
        setVisible(true);
        System.out.println("init() completed\n");
    }
    public void setFrame(){
        setSize(400, 500);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setResizable(false);
        setFocusable(true);
        setLocationRelativeTo(null);
        System.out.println("Frame set");
    }
    public void setDirectories(){
        lmdirectory = new File("Resources/LevelMaps");
        tsdirectory = new File("Resources/TileSets");
        comboBox = new JComboBox<String>();
        comboBox1 = new JComboBox<String>();

        tsList = tsdirectory.listFiles();
        tslist = new String[tsList.length];
        for (int i = 0; i < tsList.length; ++i){
            tslist[i] = tsList[i].getName();
            comboBox.addItem(tslist[i]);
        }
        lmList = lmdirectory.listFiles();
        lmlist = new String[lmList.length];
        for (int i = 0; i < lmList.length; ++i){
            lmlist[i] = lmList[i].getName();
            comboBox1.addItem(lmlist[i]);
        }
        System.out.println("Directories set");
    }
    public void setJPanels(){
        panel = new JPanel();
        panel2 = new JPanel();
        panel3 = new JPanel();
        panel4 = new JPanel();
        panel5 = new JPanel();
        panel6 = new JPanel();

        panel.add(lblTileWidth);
        panel.add(tfTileWidth);
        panel2.add(lblTileHeight);
        panel2.add(tfTileHeight);
        panel3.add(lblTileSetSourceFile);
        panel3.add(comboBox);
        panel4.add(lblLevelSourceFile);
        panel4.add(comboBox1);
        panel5.add(lblDestinationFile);
        panel5.add(tfDestinationFile);      
        panel6.add(lblHelp);
        System.out.println("JPanels set");
    }
    public void setFonts(){
        titleFont = new Font("Verdana", 1, 38);
        secondFont = new Font("Verdana", 2, 28);
        generateFont = new Font("Verdana", 0, 16);
        System.out.println("Fonts Set");
    }
    public void setJLabels(){
        lbltitle = new JLabel("Dafon's World:");
        lbltitle.setFont(titleFont);
        lbltitle.setAlignmentX(JLabel.CENTER_ALIGNMENT);

        lblsecondTitle = new JLabel("Level Generator");
        lblsecondTitle.setFont(secondFont);
        lblsecondTitle.setAlignmentX(JLabel.CENTER_ALIGNMENT);

        lblemptyString = new JLabel(" ");
        lblemptyString.setFont(secondFont);

        lblemptyString2 = new JLabel(" ");
        lblemptyString2.setFont(secondFont);

        lblauthor = new JLabel("Created by Brett A. Blashko", SwingConstants.RIGHT);

        lblcomment = new JLabel("** Please you enter all of the fields below **");
        lblcomment.setForeground(Color.red);
        lblcomment.setAlignmentX(CENTER_ALIGNMENT);

        lblTileWidth = new JLabel("Tile Width:     ");
        lblTileHeight = new JLabel("Tile Height:    ");

        lblDestinationFile = new JLabel("TileMap Destination Filename (.txt):");
        lblLevelSourceFile = new JLabel("Level Source Filename (.png):");
        lblTileSetSourceFile = new JLabel("TileSet Source Filename (.png):");

        lblHelp = new JLabel();
        lblHelp.setText("**One or more fields have been filled in incorrectly**");
        lblHelp.setForeground(Color.red);
        lblHelp.setAlignmentX(JLabel.CENTER_ALIGNMENT);
        System.out.println("JLabels set");
    }
    public void setJButton(){
        generate = new JButton("Generate!");
        generate.setAlignmentX(CENTER_ALIGNMENT);
        generate.setLayout(null);
        generate.setPreferredSize(new Dimension(600, 40));
        generate.setFont(generateFont);
    }
    public void setJTextFields(){
        tfTileWidth = new JTextField("", 12);
        tfTileHeight = new JTextField("", 12);
        tfDestinationFile = new JTextField("", 12);
        tfLevelSourceFile = new JTextField("", 12);
        tfTileSetSourceFile = new JTextField("", 12);   
        System.out.println("JTextFields set");
    }
    public void setBox(){
        box = Box.createVerticalBox();
        box.add(lbltitle);
        box.add(lblsecondTitle);
        box.add(lblemptyString);
        box.add(lblcomment);
        box.add(panel);
        box.add(panel2);
        box.add(panel3);
        box.add(panel4);
        box.add(panel5);
        box.add(lblemptyString2);
        box.add(generate);
        box.add(lblHelp).setVisible(false);
        System.out.println("Box set");
    }

    public void addListeners(){
        comboBox.addActionListener(new comboBoxListener());
        comboBox1.addActionListener(new comboBoxListener());
        generate.addActionListener(new ButtonPressedListener());
        tfTileWidth.addFocusListener(new tfTextListener());
        tfTileHeight.addFocusListener(new tfTextListener());
        tfDestinationFile.addFocusListener(new tfTextListener());
        tfLevelSourceFile.addFocusListener(new tfTextListener());
        tfTileSetSourceFile.addFocusListener(new tfTextListener());
        System.out.println("Listeners created");
    }

    public class comboBoxListener implements ActionListener{
        @Override
        public void actionPerformed(ActionEvent e) {
            if(e.getSource() == comboBox){
                i = 2;
                String s = "Resources/TileSets/" + comboBox.getItemAt(comboBox.getSelectedIndex());
                fTileSetSource = new File(s);
                comboBox.setBackground(Color.green);
                checkInputs++;
            }
            if(e.getSource() == comboBox1){
                i = 3;
                String s = "Resources/LevelMaps/" + comboBox1.getItemAt(comboBox1.getSelectedIndex());
                fLevelSource = new File(s);
                comboBox1.setBackground(Color.green);
                checkInputs++;
            }
        }
    }
    public class tfTextListener implements FocusListener{
        public void focusGained(FocusEvent e) {
            if(e.getSource() == tfTileWidth){
                tfTileWidth.setBackground(Color.white);
                i = 0;
            }
            if(e.getSource() == tfTileHeight){
                tfTileHeight.setBackground(Color.white);
                i = 1;
            }
            if(e.getSource() == tfDestinationFile){
                tfDestinationFile.setBackground(Color.white);
                i = 4;
            }
        }
        public void focusLost(FocusEvent e) {

            if(e.getSource() == tfTileWidth){
                tileWidth = tfTileWidth.getText();
                stringType(tileWidth);
            }
            if(e.getSource() == tfTileHeight){
                tileHeight = tfTileHeight.getText();
                stringType(tileHeight);
            }
            if(e.getSource() == tfTileSetSourceFile){
                tilesetSource = tfTileSetSourceFile.getText();
                stringType(tilesetSource);
            }

            if(e.getSource() == tfLevelSourceFile){
                levelSource = tfLevelSourceFile.getText();
                stringType(levelSource);
            }
            if(e.getSource() == tfDestinationFile){
                destination = tfDestinationFile.getText();
                stringType(destination);
            }
        }
    }

    public static void stringType(String str) {
        int length = 0;
        length = str.length();
        if (i >= 0 && i < 2) {
            try {
                int d = (int)Double.parseDouble(str);
                if(i == 0){
                    dTileWidth = d;
                    tfTileWidth.setBackground(Color.green);
                    checkInputs++;

                }else if(i == 1){
                    dTileHeight = d;
                    tfTileHeight.setBackground(Color.green);
                    checkInputs++;

                }
                System.out.println("Entry is valid number");


            } catch (NumberFormatException nfe) {
                System.out.println("Entry is not valid number");
                if(i == 0){
                    tfTileWidth.setBackground(Color.red);
                }else if(i == 1){
                    tfTileHeight.setBackground(Color.red);
                }
            }
        } else {
            length = str.length();
            if (str.matches("[a-zA-Z._0-9]+") && length >= 4 && length != 0) {
                if(i == 2){
                    if (str.substring(length - 4, length).equals(".png")) {
                        System.out.println("Entry is a valid String");
                        String file = ("Resources/TileSets/" + str);
                        fTileSetSource = new File(file);
                        if(fTileSetSource.exists()) { 
                            tfTileSetSourceFile.setBackground(Color.green);
                            checkInputs++;
                        }else{
                            tfTileSetSourceFile.setBackground(Color.red);
                        }
                    }
                }else if(i == 3){
                    if (str.substring(length - 4, length).equals(".png")) {
                        System.out.println("Entry is a valid String");
                        String file = ("Resources/LevelMaps/" + str);
                        fLevelSource  = new File(file);
                        if(fLevelSource.exists()) { 
                            tfLevelSourceFile.setBackground(Color.green);
                            checkInputs++;
                        }else{
                            tfLevelSourceFile.setBackground(Color.red);
                        }
                    }
                }else if(i == 4){
                    if (str.substring(length - 4, length).equals(".txt")) {
                        System.out.println("Entry is a valid String");
                        tfDestinationFile.setBackground(Color.green);
                        String file = ("Resources/TileMaps/" + str);
                        fDestination = new File(file);
                        checkInputs++;
                    }
                }
            } else {
                System.out.println("Entry is not a valid String");
                if(i == 2){
                        tfTileSetSourceFile.setBackground(Color.red);
                }else if(i == 3){
                        tfLevelSourceFile.setBackground(Color.red);
                }else if(i == 4){
                        tfDestinationFile.setBackground(Color.red);

                }
            }
        }
    }
    public class ButtonPressedListener implements ActionListener{
        public void actionPerformed(ActionEvent e){
            if(checkInputs >= 5){
                dispose();
                Generator gen = new Generator();
                gen.setDefaultCloseOperation(EXIT_ON_CLOSE);
            }else{
                box.getComponent(11).setVisible(true);
                repaint();              
            }
        }
    }   
    public void lsetvisible(boolean b){
        setVisible(b);
    }
}
导入java.awt.BorderLayout;
导入java.awt.Color;
导入java.awt.Dimension;
导入java.awt.Font;
导入java.awt.event.ActionEvent;
导入java.awt.event.ActionListener;
导入java.awt.event.FocusEvent;
导入java.awt.event.FocusListener;
导入java.io.File;
导入javax.swing.Box;
导入javax.swing.JButton;
导入javax.swing.JComboBox;
导入javax.swing.JFrame;
导入javax.swing.JLabel;
导入javax.swing.JPanel;
导入javax.swing.JTextField;
导入javax.swing.SwingConstants;
@抑制警告(“串行”)
公共类启动器扩展JFrame{
公共静态字体标题;
公共静态字体;
公共静态字体生成器;
公共静态输入高度;
公共静态int levelWidth;
公共静态字符串平铺宽度;
公共静态字符串tileHeight;
公共静态字符串目的地;
公共静态字符串源;
公共静态字符串tilesetSource;
公共静态整数分位数;
公共静态输入光;
公共静电箱;
公共静态JPanel面板;
公共静态JPanel Panel 1;
公共静态JPanel panel2;
公共静态JPanel panel3;
公共静态JPanel panel4;
公共静态JPanel面板5;
公共静态JPanel panel6;
公共静态JLabel-lbltite;
公共静态JLabel lblsecondTitle;
公共静态JLabel-lblemptyString;
公共静态JLabel lblemptyString2;
公共静态JLabel lblcomment;
公共静态JLabel-lblautor;
公共静态JLabel lblTileWidth;
公共静态JLabel-lbltilehight;
公共静态JLabel lbld目标文件;
公共静态JLabel lblLevelSourceFile;
公共静态JLabel lblTileSetSourceFile;
公共静态JLabel lblHelp;
公共静态按钮生成;
公共静态jtextfilewidth字段;
公共静态jtextfileheight字段;
公共静态JTextField tfDestinationFile;
公共静态JTextField tfLevelSourceFile;
公共静态jtextfilesetsourcefile;
公共静态整数宽度;
公共静态int-dHeight;
公共静态int-dTileWidth;
公共静态整数高度;
公共静态int dTilesetHeight;
公共静态int-dTilesetWidth;
公共静态文件定义;
公共静态文件源;
公共静态文件fTileSetSource;
公共静态文件目录;
公共静态文件目录;
公共静态文件[]tsList;
公共静态文件列表;
公共静态字符串[]tslist;
公共静态字符串[]lmlist;
公共静态INTI;
公共静态int校验输入;
专用JComboBox组合框;
专用JComboxCombox1;
公共启动器(){
超级(“达丰的世界:水平发生器”);
init();
}
公共void init(){
i=0;
检查输入=0;
setFrame();
setDirectories();
setFonts();
setJLabels();
setJButton();
setJTextFields();
setJPanels();
setBox();
addListeners();
添加(框,边框布局。北);
添加(LBLAUTOR,BorderLayout.SOUTH);
setVisible(真);
System.out.println(“init()已完成\n”);
}
公共void setFrame(){
设置大小(400500);
setDefaultCloseOperation(关闭时退出);
可设置大小(假);
设置聚焦(真);
setLocationRelativeTo(空);
系统输出打印项次(“帧集”);
}
public void setDirectories(){
lmdirectory=新文件(“资源/LevelMaps”);
tsdirectory=新文件(“资源/TileSets”);
comboBox=新的JComboBox();
comboBox1=新的JComboBox();
tsList=tsdirectory.listFiles();
tslist=新字符串[tslist.length];
对于(int i=0;iimport java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.io.File;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

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

    public static Font titleFont;
    public static Font secondFont;
    public static Font generateFont;

    public static int levelHeight;
    public static int levelWidth;
    public static String tileWidth;
    public static String tileHeight;
    public static String destination;
    public static String levelSource;
    public static String tilesetSource;
    public static int tilesetWidth;
    public static int tilesetHeight;

    public static Box box;

    public static JPanel panel;
    public static JPanel panel1;
    public static JPanel panel2;
    public static JPanel panel3;
    public static JPanel panel4;
    public static JPanel panel5;
    public static JPanel panel6;    

    public static JLabel lbltitle;
    public static JLabel lblsecondTitle;
    public static JLabel lblemptyString;
    public static JLabel lblemptyString2;
    public static JLabel lblcomment;
    public static JLabel lblauthor;
    public static JLabel lblTileWidth;
    public static JLabel lblTileHeight;
    public static JLabel lblDestinationFile;
    public static JLabel lblLevelSourceFile;
    public static JLabel lblTileSetSourceFile;
    public static JLabel lblHelp;

    public static JButton generate;

    public static JTextField tfTileWidth;
    public static JTextField tfTileHeight;
    public static JTextField tfDestinationFile;
    public static JTextField tfLevelSourceFile;
    public static JTextField tfTileSetSourceFile;

    public static int dWidth;
    public static int dHeight;
    public static int dTileWidth;
    public static int dTileHeight;
    public static int dTilesetHeight;
    public static int dTilesetWidth;

    public static File fDestination;
    public static File fLevelSource;
    public static File fTileSetSource;

    public static File tsdirectory;
    public static File lmdirectory;

    public static File[] tsList;
    public static File[] lmList;

    public static String[] tslist;
    public static String[] lmlist;

    public static int i;
    public static int checkInputs;

    private JComboBox<String> comboBox;
    private JComboBox<String> comboBox1;    

    public Launcher(){
        super("Dafon's World: Level Generator");
        init();
    }
    public void init(){
        i = 0;
        checkInputs = 0;
        setFrame();
        setDirectories();
        setFonts();
        setJLabels();
        setJButton();
        setJTextFields();
        setJPanels();
        setBox();
        addListeners();

        add(box, BorderLayout.NORTH);
        add(lblauthor, BorderLayout.SOUTH);
        setVisible(true);
        System.out.println("init() completed\n");
    }
    public void setFrame(){
        setSize(400, 500);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setResizable(false);
        setFocusable(true);
        setLocationRelativeTo(null);
        System.out.println("Frame set");
    }
    public void setDirectories(){
        lmdirectory = new File("Resources/LevelMaps");
        tsdirectory = new File("Resources/TileSets");
        comboBox = new JComboBox<String>();
        comboBox1 = new JComboBox<String>();

        tsList = tsdirectory.listFiles();
        tslist = new String[tsList.length];
        for (int i = 0; i < tsList.length; ++i){
            tslist[i] = tsList[i].getName();
            comboBox.addItem(tslist[i]);
        }
        lmList = lmdirectory.listFiles();
        lmlist = new String[lmList.length];
        for (int i = 0; i < lmList.length; ++i){
            lmlist[i] = lmList[i].getName();
            comboBox1.addItem(lmlist[i]);
        }
        System.out.println("Directories set");
    }
    public void setJPanels(){
        panel = new JPanel();
        panel2 = new JPanel();
        panel3 = new JPanel();
        panel4 = new JPanel();
        panel5 = new JPanel();
        panel6 = new JPanel();

        panel.add(lblTileWidth);
        panel.add(tfTileWidth);
        panel2.add(lblTileHeight);
        panel2.add(tfTileHeight);
        panel3.add(lblTileSetSourceFile);
        panel3.add(comboBox);
        panel4.add(lblLevelSourceFile);
        panel4.add(comboBox1);
        panel5.add(lblDestinationFile);
        panel5.add(tfDestinationFile);      
        panel6.add(lblHelp);
        System.out.println("JPanels set");
    }
    public void setFonts(){
        titleFont = new Font("Verdana", 1, 38);
        secondFont = new Font("Verdana", 2, 28);
        generateFont = new Font("Verdana", 0, 16);
        System.out.println("Fonts Set");
    }
    public void setJLabels(){
        lbltitle = new JLabel("Dafon's World:");
        lbltitle.setFont(titleFont);
        lbltitle.setAlignmentX(JLabel.CENTER_ALIGNMENT);

        lblsecondTitle = new JLabel("Level Generator");
        lblsecondTitle.setFont(secondFont);
        lblsecondTitle.setAlignmentX(JLabel.CENTER_ALIGNMENT);

        lblemptyString = new JLabel(" ");
        lblemptyString.setFont(secondFont);

        lblemptyString2 = new JLabel(" ");
        lblemptyString2.setFont(secondFont);

        lblauthor = new JLabel("Created by Brett A. Blashko", SwingConstants.RIGHT);

        lblcomment = new JLabel("** Please you enter all of the fields below **");
        lblcomment.setForeground(Color.red);
        lblcomment.setAlignmentX(CENTER_ALIGNMENT);

        lblTileWidth = new JLabel("Tile Width:     ");
        lblTileHeight = new JLabel("Tile Height:    ");

        lblDestinationFile = new JLabel("TileMap Destination Filename (.txt):");
        lblLevelSourceFile = new JLabel("Level Source Filename (.png):");
        lblTileSetSourceFile = new JLabel("TileSet Source Filename (.png):");

        lblHelp = new JLabel();
        lblHelp.setText("**One or more fields have been filled in incorrectly**");
        lblHelp.setForeground(Color.red);
        lblHelp.setAlignmentX(JLabel.CENTER_ALIGNMENT);
        System.out.println("JLabels set");
    }
    public void setJButton(){
        generate = new JButton("Generate!");
        generate.setAlignmentX(CENTER_ALIGNMENT);
        generate.setLayout(null);
        generate.setPreferredSize(new Dimension(600, 40));
        generate.setFont(generateFont);
    }
    public void setJTextFields(){
        tfTileWidth = new JTextField("", 12);
        tfTileHeight = new JTextField("", 12);
        tfDestinationFile = new JTextField("", 12);
        tfLevelSourceFile = new JTextField("", 12);
        tfTileSetSourceFile = new JTextField("", 12);   
        System.out.println("JTextFields set");
    }
    public void setBox(){
        box = Box.createVerticalBox();
        box.add(lbltitle);
        box.add(lblsecondTitle);
        box.add(lblemptyString);
        box.add(lblcomment);
        box.add(panel);
        box.add(panel2);
        box.add(panel3);
        box.add(panel4);
        box.add(panel5);
        box.add(lblemptyString2);
        box.add(generate);
        box.add(lblHelp).setVisible(false);
        System.out.println("Box set");
    }

    public void addListeners(){
        comboBox.addActionListener(new comboBoxListener());
        comboBox1.addActionListener(new comboBoxListener());
        generate.addActionListener(new ButtonPressedListener());
        tfTileWidth.addFocusListener(new tfTextListener());
        tfTileHeight.addFocusListener(new tfTextListener());
        tfDestinationFile.addFocusListener(new tfTextListener());
        tfLevelSourceFile.addFocusListener(new tfTextListener());
        tfTileSetSourceFile.addFocusListener(new tfTextListener());
        System.out.println("Listeners created");
    }

    public class comboBoxListener implements ActionListener{
        @Override
        public void actionPerformed(ActionEvent e) {
            if(e.getSource() == comboBox){
                i = 2;
                String s = "Resources/TileSets/" + comboBox.getItemAt(comboBox.getSelectedIndex());
                fTileSetSource = new File(s);
                comboBox.setBackground(Color.green);
                checkInputs++;
            }
            if(e.getSource() == comboBox1){
                i = 3;
                String s = "Resources/LevelMaps/" + comboBox1.getItemAt(comboBox1.getSelectedIndex());
                fLevelSource = new File(s);
                comboBox1.setBackground(Color.green);
                checkInputs++;
            }
        }
    }
    public class tfTextListener implements FocusListener{
        public void focusGained(FocusEvent e) {
            if(e.getSource() == tfTileWidth){
                tfTileWidth.setBackground(Color.white);
                i = 0;
            }
            if(e.getSource() == tfTileHeight){
                tfTileHeight.setBackground(Color.white);
                i = 1;
            }
            if(e.getSource() == tfDestinationFile){
                tfDestinationFile.setBackground(Color.white);
                i = 4;
            }
        }
        public void focusLost(FocusEvent e) {

            if(e.getSource() == tfTileWidth){
                tileWidth = tfTileWidth.getText();
                stringType(tileWidth);
            }
            if(e.getSource() == tfTileHeight){
                tileHeight = tfTileHeight.getText();
                stringType(tileHeight);
            }
            if(e.getSource() == tfTileSetSourceFile){
                tilesetSource = tfTileSetSourceFile.getText();
                stringType(tilesetSource);
            }

            if(e.getSource() == tfLevelSourceFile){
                levelSource = tfLevelSourceFile.getText();
                stringType(levelSource);
            }
            if(e.getSource() == tfDestinationFile){
                destination = tfDestinationFile.getText();
                stringType(destination);
            }
        }
    }

    public static void stringType(String str) {
        int length = 0;
        length = str.length();
        if (i >= 0 && i < 2) {
            try {
                int d = (int)Double.parseDouble(str);
                if(i == 0){
                    dTileWidth = d;
                    tfTileWidth.setBackground(Color.green);
                    checkInputs++;

                }else if(i == 1){
                    dTileHeight = d;
                    tfTileHeight.setBackground(Color.green);
                    checkInputs++;

                }
                System.out.println("Entry is valid number");


            } catch (NumberFormatException nfe) {
                System.out.println("Entry is not valid number");
                if(i == 0){
                    tfTileWidth.setBackground(Color.red);
                }else if(i == 1){
                    tfTileHeight.setBackground(Color.red);
                }
            }
        } else {
            length = str.length();
            if (str.matches("[a-zA-Z._0-9]+") && length >= 4 && length != 0) {
                if(i == 2){
                    if (str.substring(length - 4, length).equals(".png")) {
                        System.out.println("Entry is a valid String");
                        String file = ("Resources/TileSets/" + str);
                        fTileSetSource = new File(file);
                        if(fTileSetSource.exists()) { 
                            tfTileSetSourceFile.setBackground(Color.green);
                            checkInputs++;
                        }else{
                            tfTileSetSourceFile.setBackground(Color.red);
                        }
                    }
                }else if(i == 3){
                    if (str.substring(length - 4, length).equals(".png")) {
                        System.out.println("Entry is a valid String");
                        String file = ("Resources/LevelMaps/" + str);
                        fLevelSource  = new File(file);
                        if(fLevelSource.exists()) { 
                            tfLevelSourceFile.setBackground(Color.green);
                            checkInputs++;
                        }else{
                            tfLevelSourceFile.setBackground(Color.red);
                        }
                    }
                }else if(i == 4){
                    if (str.substring(length - 4, length).equals(".txt")) {
                        System.out.println("Entry is a valid String");
                        tfDestinationFile.setBackground(Color.green);
                        String file = ("Resources/TileMaps/" + str);
                        fDestination = new File(file);
                        checkInputs++;
                    }
                }
            } else {
                System.out.println("Entry is not a valid String");
                if(i == 2){
                        tfTileSetSourceFile.setBackground(Color.red);
                }else if(i == 3){
                        tfLevelSourceFile.setBackground(Color.red);
                }else if(i == 4){
                        tfDestinationFile.setBackground(Color.red);

                }
            }
        }
    }
    public class ButtonPressedListener implements ActionListener{
        public void actionPerformed(ActionEvent e){
            if(checkInputs >= 5){
                dispose();
                Generator gen = new Generator();
                gen.setDefaultCloseOperation(EXIT_ON_CLOSE);
            }else{
                box.getComponent(11).setVisible(true);
                repaint();              
            }
        }
    }   
    public void lsetvisible(boolean b){
        setVisible(b);
    }
}