Tuesday 15 March 2011

java - Program works in eclipse. But when I export to an executable it does not open the JFrame -



java - Program works in eclipse. But when I export to an executable it does not open the JFrame -

i confused @ going wrong here. believe wrong way jframe set up. there generator class think if can launcher working generator come after. help appreciated!

here source code:

main:

public class main { static launcher launcher; public static void main(string[]args){ launcher = new launcher(); } }

launcher:

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(){ = 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]; (int = 0; < tslist.length; ++i){ tslist[i] = tslist[i].getname(); combobox.additem(tslist[i]); } lmlist = lmdirectory.listfiles(); lmlist = new string[lmlist.length]; (int = 0; < 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 brett a. blashko", swingconstants.right); lblcomment = new jlabel("** please come in of 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){ = 2; string s = "resources/tilesets/" + combobox.getitemat(combobox.getselectedindex()); ftilesetsource = new file(s); combobox.setbackground(color.green); checkinputs++; } if(e.getsource() == combobox1){ = 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); = 0; } if(e.getsource() == tftileheight){ tftileheight.setbackground(color.white); = 1; } if(e.getsource() == tfdestinationfile){ tfdestinationfile.setbackground(color.white); = 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 && < 2) { seek { 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 valid number"); } grab (numberformatexception nfe) { system.out.println("entry 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 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 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 valid string"); tfdestinationfile.setbackground(color.green); string file = ("resources/tilemaps/" + str); fdestination = new file(file); checkinputs++; } } } else { system.out.println("entry not 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 swing jframe embedded-resource executable-jar

No comments:

Post a Comment