i'm writing simple program have multiple jframe
windows when use multiple stack , i've tried set visibility false isn't working i'm trying simulate close frames don't stack on top of each other don't know use since program isn't window.
public void close(){ windowevent winclosingevent = new windowevent(this, windowevent.window_closing); toolkit.getdefaulttoolkit().getsystemeventqueue().postevent(winclosingevent); }
on this keep getting error of
incompatible types: program1 cannot converted window
if has better way of doing please let me know cant find better way that's working me.
import java.awt.color; import java.awt.font; import java.awt.toolkit; import java.awt.event.windowevent; import java.io.file; import java.io.ioexception; import java.util.arraylist; import java.util.date; import javax.sound.sampled.audiosystem; import javax.sound.sampled.clip; import javax.sound.sampled.lineunavailableexception; import javax.sound.sampled.unsupportedaudiofileexception; import javax.swing.imageicon; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.joptionpane; import javax.swing.jpanel; //http://vignette4.wikia.nocookie.net/bioshock/images/b/ba/monu_island-skyline01.png/revision/latest?cb=20130521042740 public class program1 { public string welcome() { date date = new date(); file music = new file("bioshock_infinite_-_bioshock_infinite_-_after_youv.wav"); try { clip clip = audiosystem.getclip(); clip.open(audiosystem.getaudioinputstream(music)); clip.start(); } catch (lineunavailableexception | unsupportedaudiofileexception | ioexception e) { } jframe welcomejframe = new jframe("welcome daimeon's escape!"); jlabel backgroundimagejlabel = new jlabel(); backgroundimagejlabel.seticon(new imageicon("monu_island-skyline01.png")); jlabel gamenamejlabel = new jlabel("an escape monument island!"); jlabel welcomejlabel = new jlabel("welcome daimeon's escape game."); jlabel currentdatejlabel = new jlabel("" + date.tostring() + ""); jpanel panel = new jpanel(); welcomejframe.setdefaultcloseoperation(jframe.exit_on_close); currentdatejlabel.setbounds(400, 700, 800, 60); currentdatejlabel.setfont(new font("andes", font.bold, 60)); currentdatejlabel.sethorizontalalignment(jlabel.center); gamenamejlabel.setbounds(350, 15, 900, 60); gamenamejlabel.setforeground(color.red); gamenamejlabel.setfont(new font("andes", font.bold, 60)); gamenamejlabel.sethorizontalalignment(jlabel.center); welcomejlabel.setbounds(450, 75, 700, 35); welcomejlabel.setfont(new font("andes", font.bold, 30)); welcomejlabel.sethorizontalalignment(jlabel.center); panel.add(backgroundimagejlabel); backgroundimagejlabel.add(gamenamejlabel); backgroundimagejlabel.add(welcomejlabel); backgroundimagejlabel.add(currentdatejlabel); welcomejframe.add(panel); welcomejframe.setsize(1828, 1080); welcomejframe.setlocationrelativeto(null); welcomejframe.setvisible(true); string name = ""; name = getusers_name(name); gretting(name); return name; } public string getusers_name(string name) { return name = joptionpane.showinputdialog(null, "hey there please sign-in name:"); } public void gretting(string name) { joptionpane.showmessagedialog(null, "well howdy there " + name + " welcome website." + "\nheres run down of about."); joptionpane.showmessagedialog(null, name + "\n stuck in monument on monument island trying escape" + "\n songbrid , sherpards men, both trying kill" + " you."); joptionpane.showmessagedialog(null, "\t \t \t basic registration fees\n" + "$2.50 : dont run before can walk " + "( ages 0 - 4 )\n" + "$5.00 : felling courageous " + "( ages 4 - 12 )\n" + "$7.50 : wont walk in park " + "( ages 13 - 17 )\n" + "$9.75 : expert " + "( ages 18+ )\n" + "$1.25 : additional items " + "( lock pick, silver eagle or creature )", "fees", joptionpane.warning_message, null); joptionpane.showmessagedialog(null, "hey " + name + ",\n" + "please continue start\n" + "registration", "please continue", joptionpane.warning_message, null); } public void start_regstration(arraylist users_information) { int[] user_number_information = new int[5]; int addons = 0; double[] user_dep_amount = new double[5]; users_information.add(get_user_alias(users_information)); users_information.add(get_user_gender(users_information)); users_information.add(get_user_atrological_sign(users_information)); user_number_information[0] = get_user_birth_year(users_information); user_dep_amount[0] = get_int_player_dep_amount(users_information); user_number_information[2] = get_addon_1(users_information); user_number_information[3] = get_addon_2(users_information); user_number_information[4] = get_addon_3(users_information); confirm(users_information, user_number_information); compute_total_addons(user_number_information); feature_recipt(users_information, user_number_information); pre_total_reg_fee_recipt(users_information, user_number_information); user_number_information[1] = get_players_age(user_number_information); user_dep_amount[1] = players_age_reg_fee(user_number_information); user_dep_amount[2] = daimeons_round_to_penny(user_number_information); final_player_fee_amount(users_information, user_dep_amount); exit_m(); } public string get_user_alias(arraylist users_information) { string alias; alias = (string) joptionpane.showinputdialog(null, "hey " + users_information.get(0) + " alias?", "alias", joptionpane.question_message, null, null, "captain"); return alias; } public string get_user_gender(arraylist users_information) { string user_gender; user_gender = (string) joptionpane.showinputdialog(null, "hey " + users_information.get(1) + " gender?", "gender", joptionpane.question_message, null, null, "male"); return user_gender; } public string get_user_atrological_sign(arraylist users_information) { close(); string astro_sign; astro_sign = (string) joptionpane.showinputdialog(null, "hey " + users_information.get(1) + " what's astrological sign?", "astrological sign", joptionpane.question_message, null, null, "gemini"); return astro_sign; } public int get_user_birth_year(arraylist users_information) { int by; string input = joptionpane.showinputdialog(null, "hey " + users_information.get(1) + " birth year?"); = integer.parseint(input); return by; } public double get_int_player_dep_amount(arraylist users_information) { double user_dep; object input = joptionpane.showinputdialog(null, "hey " + users_information.get(1) + " how deposit?", "deposit", joptionpane.question_message, null, null, "1234.56"); user_dep = double.parsedouble((string) input); return user_dep; } public int get_addon_1(arraylist users_information) { return 1; } public int extrafeaturetreasure( string alias )
{
//title bar jframe getextrafeaturesjframe = new jframe("user's features" ); //set background jlabel backgroundimagejlabel = new jlabel( ); backgroundimagejlabel.seticon( new imageicon( "vv.jpg" ) ); //treasure jlabel treasurejlabel = new jlabel( ); //creatures jlabel creature1jlabel = new jlabel( ); jlabel creature2jlabel = new jlabel( ); //key jlabel keyjlabel = new jlabel( ); //second panel jpanel thesecondpanel = new jpanel( ); getextrafeaturesjframe.setdefaultcloseoperation( jframe.exit_on_close ); treasurejlabel.seticon( new imageicon( "lovee.gif" ) ); creature1jlabel.seticon( new imageicon( "gun.gif" ) ); creature2jlabel.seticon( new imageicon( "creature2.gif" ) ); keyjlabel.seticon( new imageicon( "fashionkey.jpg" ) ); //extra feature price label jlabel extrafeaturetextjlabel = new jlabel( "extra features : $1.25 ea" ); //treasure jlabel treasuretextjlabel = new jlabel( "treasure" ); jlabel treasuredescriptiontext0jlabel = new jlabel( "extra treasures of the" ); jlabel treasuredescriptiontext1jlabel = new jlabel( "latest fashion trends!" ); //creature jlabel creature1textjlabel = new jlabel( "the guy gun" ); jlabel creature2textjlabel = new jlabel( "unfashionable shopaholics" ); jlabel creature1textdescription0jlabel = new jlabel( "beware of creatures!" ); jlabel creature1textdescription1jlabel = new jlabel( "if encounter @ point" ); jlabel creature1textdescription2jlabel = new jlabel( "you lose precious shops" ); //key jlabel keytextjlabel = new jlabel( "fashion key" ); jlabel keytextdescription0jlabel = new jlabel( "fashion keys most" ); jlabel keytextdescription1jlabel = new jlabel( "special features in game" ); jlabel keytextdescription2jlabel = new jlabel( "since add final touch" ); jlabel keytextdescription3jlabel = new jlabel( "to perfect outfit" ); //extra feature label characteristics extrafeaturetextjlabel.setfont( new font( "cooper black", font.bold, 40 ) ); extrafeaturetextjlabel.setforeground( new color( 250, 150, 200 )); extrafeaturetextjlabel.sethorizontalalignment( jlabel.center ); //extra feature label characteristics treasuretextjlabel.setfont( new font( "cooper black", font.bold, 25 ) ); treasuredescriptiontext0jlabel.setfont( new font( "cooper black", font.bold, 20 ) ); treasuredescriptiontext1jlabel.setfont( new font( "cooper black", font.bold, 20 ) ); //extra feature label characteristics creature1textjlabel.setfont( new font( "cooper black", font.bold, 25 ) ); creature1textdescription0jlabel.setfont( new font( "cooper black", font.bold, 20 ) ); creature1textdescription1jlabel.setfont( new font( "cooper black", font.bold, 20 ) ); creature1textdescription2jlabel.setfont( new font( "cooper black", font.bold, 20 ) ); //extra feature label characteristics creature2textjlabel.setfont( new font( "cooper black", font.bold, 25 ) ); //extra feature label characteristics keytextjlabel.setfont( new font( "cooper black", font.bold, 25 ) ); keytextdescription0jlabel.setfont( new font( "cooper black", font.bold, 20 ) ); keytextdescription1jlabel.setfont( new font( "cooper black", font.bold, 20 ) ); keytextdescription2jlabel.setfont( new font( "cooper black", font.bold, 20 ) ); keytextdescription3jlabel.setfont( new font( "cooper black", font.bold, 20 ) ); //extra feature label characteristics extrafeaturetextjlabel.setbounds( 450,1,700,40 ); treasuretextjlabel.setbounds( 400,315,500,50 ); treasurejlabel.setbounds( 200,35,500,300 ); treasuredescriptiontext0jlabel.setbounds( 200,345,500,50 ); treasuredescriptiontext1jlabel.setbounds( 200,365,500,50 ); keytextjlabel.setbounds( 1195,284,500,50 ); keyjlabel.setbounds( 1132,45,400,250 ); keytextdescription0jlabel.setbounds( 770,20,400,250 ); keytextdescription1jlabel.setbounds( 770,40,400,250 ); keytextdescription2jlabel.setbounds( 770,60,400,250 ); keytextdescription3jlabel.setbounds( 770,80,400,250 ); creature1textjlabel.setbounds( 300,645,500,50 ); creature2textjlabel.setbounds( 980,645,545,50 ); creature1textdescription0jlabel.setbounds( 200,675,500,50 ); creature1textdescription1jlabel.setbounds( 200,695,500,50 ); creature1textdescription2jlabel.setbounds( 200,715,500,50 ); creature1jlabel.setbounds( 200,390,500,300 ); creature2jlabel.setbounds( 897,377,500,300 ); //add labels pannel thesecondpanel.add(backgroundimagejlabel); backgroundimagejlabel.add(extrafeaturetextjlabel); backgroundimagejlabel.add(treasuretextjlabel); backgroundimagejlabel.add(treasurejlabel); backgroundimagejlabel.add(treasuredescriptiontext0jlabel); backgroundimagejlabel.add(treasuredescriptiontext1jlabel); backgroundimagejlabel.add(creature1textjlabel); backgroundimagejlabel.add(creature1jlabel); backgroundimagejlabel.add(creature2textjlabel); backgroundimagejlabel.add(creature2jlabel); backgroundimagejlabel.add(creature1textdescription0jlabel); backgroundimagejlabel.add(creature1textdescription1jlabel); backgroundimagejlabel.add(creature1textdescription2jlabel); backgroundimagejlabel.add(keytextjlabel); backgroundimagejlabel.add(keyjlabel); backgroundimagejlabel.add(keytextdescription0jlabel); backgroundimagejlabel.add(keytextdescription1jlabel); backgroundimagejlabel.add(keytextdescription2jlabel); backgroundimagejlabel.add(keytextdescription3jlabel); //add panel frame getextrafeaturesjframe.add(thesecondpanel); getextrafeaturesjframe.setsize ( 1280, 900 ); getextrafeaturesjframe.setlocationrelativeto( null ); getextrafeaturesjframe.setvisible( true ); //ask user's amount deposit, output changes string object //image 2 object gettreasures = joptionpane.showinputdialog( null, "dear " + alias + "\u2661,\n" +"please enter number of treasures\n" +"you wish acquire", "\u2661number of treasures\u2661", joptionpane.plain_message, icon, null, "0"); //typecast, converts returned object string getusertreasures = (string)gettreasures; //converts returned string int numberoftreasures = integer.parseint( getusertreasures ); return numberoftreasures;
}
public int get_addon_2(arraylist users_information) { return 2; } public int get_addon_3(arraylist users_information) { return 3; } public void confirm(arraylist users_information, int[] user_number_information) { } public double compute_total_addons(int[] user_number_information) { return 1.0; } public void feature_recipt(arraylist users_information, int[] user_number_information) { } public void pre_total_reg_fee_recipt(arraylist users_information, int[] user_number_information) { } public int get_players_age(int[] user_number_information) { return 1; } public double players_age_reg_fee(int[] user_number_information) { return 1.0; } public double daimeons_round_to_penny(int[] user_number_information) { return 1.0; } public void final_player_fee_amount(arraylist users_information, double[] user_dep_amount) { } public void exit_m() { system.exit(0); } public void close() { // todo: fix: // windowevent winclosingevent = new windowevent(this, // windowevent.window_closing); // toolkit.getdefaulttoolkit().getsystemeventqueue().postevent(winclosingevent); } public static void main(string[] args) { program1 methods = new program1(); arraylist<string> users_information = new arraylist<>(); users_information.add(methods.welcome()); methods.start_regstration(users_information); methods.extrafeaturetreasure(); } }
you didn't put enough information , explanation exact problem here can : make jframe close when click on os provided close button (at top right corner usually) work (put in class controlls jframe extends jframe class ) :
this.setdefaultcloseoperation(jframe.exit_on_close);
to close jframe on specific event use :
this.dispose();
to make jframe invisible use :
this.setvisible(false);
Comments
Post a Comment