java - Giving action listeners string qualities and using those strings in an if statement -


as sort of side project teach myself action listeners, buttons, , jframes started bit of profiler based on tv shows , like. buttons , actionlisteners work can't figure out how give action listeners strings , call on strings. going wrong? thank in advance.

import java.awt.graphics; import java.awt.event.actionevent; import java.awt.event.actionlistener; import java.awt.image.bufferedimage; import java.io.ioexception; import java.net.url; import javax.imageio.imageio; import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.jpanel; public class profilecreatorwithoutrecords extends jframe {  public static void main(string[] args) throws ioexception { final string dramaanswer; final string comedystyleanswer; final string comedyshowanswer;  final jframe fridayframe = new jframe(); fridayframe.setcontentpane(new jpanel() {     bufferedimage image = imageio.read(new url("http://s21.postimg.org/xfdlwcr2f/friday_night_lights_season_4_pictures.jpg"));     public void paintcomponent(graphics g) {         super.paintcomponent(g);         g.drawimage(image, 0, 0, 500, 350, this);     } }); final jbutton fridaybutton = new jbutton("friday night lights"); fridayframe.add(fridaybutton); fridayframe.setdefaultcloseoperation(exit_on_close); fridayframe.setsize(500, 350); fridayframe.setvisible(true); fridayframe.setlocation(0, 0);  ///////////////////////////////////////////////////////////////////mad men final jframe madframe = new jframe(); madframe.setcontentpane(new jpanel() {     bufferedimage image = imageio.read(new url("http://s27.postimg.org/c1lxi135v/mad_men_1024x768.jpg"));     public void paintcomponent(graphics g) {         super.paintcomponent(g);         g.drawimage(image, 0, 0, 1024, 768, this);     } });  final jbutton madbutton = new jbutton("mad men"); madframe.add(madbutton); madframe.setdefaultcloseoperation(jframe.exit_on_close); madframe.setsize(1024, 768); madframe.setvisible(true); madframe.setlocation(900,0);  ////////////////////////////////////////house of cards  final jframe houseframe = new jframe(); houseframe.setcontentpane(new jpanel() {     bufferedimage image = imageio.read(new url("http://cdn.bgr.com/2013/04/netflix-house-of-cards.jpg"));     public void paintcomponent(graphics g) {         super.paintcomponent(g);         g.drawimage(image, 0, 0, 620, 458, this);     } }); final jbutton housebutton = new jbutton("house of cards"); houseframe.setvisible(true); houseframe.setsize(620, 458); houseframe.setdefaultcloseoperation(exit_on_close); houseframe.add(housebutton); houseframe.setlocation(0, 400);  //////////////////////////////////////////////////////////////////////////////////gaffigan  final jframe gaffiganframe = new jframe(); gaffiganframe.setcontentpane(new jpanel() {     bufferedimage image = imageio.read(new url("http://thepost.s3.amazonaws.com/wp-content/uploads/2015/02/jim-gaffigan-wilbur-artist1.jpg"));     public void paintcomponent(graphics g) {         super.paintcomponent(g);         g.drawimage(image, 0, 0, 550, 253, this);     } }); final jbutton gaffiganbutton = new jbutton("clean comedy"); gaffiganframe.setvisible(false); gaffiganframe.setsize(550, 253); gaffiganframe.setdefaultcloseoperation(exit_on_close); gaffiganframe.add(gaffiganbutton); gaffiganframe.setlocation(0, 0);  ///////////////////////////////////////////////////////////////////////////////////louie final jframe louieframe = new jframe(); louieframe.setcontentpane(new jpanel() {     bufferedimage image = imageio.read(new url("http://static.dudeiwantthat.com/omg/video-clips/louis-ck-live-at-the-beacon-theater-1604.jpg"));     public void paintcomponent(graphics g) {         super.paintcomponent(g);         g.drawimage(image, 0, 0, 504, 420, this);     } }); final jbutton louiebutton = new jbutton("dirty, rant comedy"); louieframe.setvisible(false); louieframe.setsize(504, 420); louieframe.setdefaultcloseoperation(exit_on_close); louieframe.add(louiebutton); louieframe.setlocation(500, 0);  final jframe officeframe = new jframe(); officeframe.setcontentpane(new jpanel() {     bufferedimage image = imageio.read(new url("https://sarahsayswatchit.files.wordpress.com/2011/05/the-office.jpg"));     public void paintcomponent(graphics g) {         super.paintcomponent(g);         g.drawimage(image, 0, 0, 600, 600, this);     } }); final jbutton officebutton = new jbutton("the office"); officeframe.setvisible(false); officeframe.setsize(600, 600); officeframe.setdefaultcloseoperation(exit_on_close); officeframe.add(officebutton); officeframe.setlocation(0, 0);  final jframe southframe = new jframe(); southframe.setcontentpane(new jpanel() {     bufferedimage image = imageio.read(new url("http://2.images.southparkstudios.com/default/image.jpg?quality=0.8"));     public void paintcomponent(graphics g) {         super.paintcomponent(g);         g.drawimage(image, 0, 0, 480, 360, this);     } }); final jbutton southbutton = new jbutton("south park"); southframe.setvisible(false); southframe.setsize(480, 360); southframe.setdefaultcloseoperation(exit_on_close); southframe.add(southbutton); southframe.setlocation(650, 0);  final jframe bigbangframe = new jframe(); bigbangframe.setcontentpane(new jpanel() {     bufferedimage image = imageio.read(new url("http://1.bp.blogspot.com/-w8v5fzjwadk/u_nlrh73i5i/aaaaaaaabsu/02yuf3ips78/s1600/the-big-bang-theory%3dsatanismo.png"));     public void paintcomponent(graphics g) {         super.paintcomponent(g);         g.drawimage(image, 0, 0, 1000, 562, this);     } }); final jbutton bigbangbutton = new jbutton("big boob blonde lady"); bigbangframe.setvisible(false); bigbangframe.setsize(1000, 562); bigbangframe.setdefaultcloseoperation(exit_on_close); bigbangframe.add(bigbangbutton); bigbangframe.setlocation(0, 800);  fridaybutton.addactionlistener(new actionlistener() {     public void actionperformed(actionevent fridayclicked) {         string dramaanswer = "fridaynightlights";         fridayframe.setvisible(false);         madframe.setvisible(false);         houseframe.setvisible(false);         gaffiganframe.setvisible(true);         louieframe.setvisible(true);     } });  madbutton.addactionlistener(new actionlistener() {     @override     public void actionperformed(actionevent madclicked) {         dramaanswer = "madmen";         madframe.setvisible(false);         fridayframe.setvisible(false);         houseframe.setvisible(false);         gaffiganframe.setvisible(true);         louieframe.setvisible(true);     } });  housebutton.addactionlistener(new actionlistener() {     @override     public void actionperformed(actionevent houseclicked) {         dramaanswer = "houseofcards";         fridayframe.setvisible(false);         houseframe.setvisible(false);         madframe.setvisible(false);         louieframe.setvisible(true);         gaffiganframe.setvisible(true);     }  });  gaffiganbutton.addactionlistener(new actionlistener() {     @override     public void actionperformed(actionevent cleanpicked) {         comedystyleanswer = "cleancomedy";         louieframe.setvisible(false);         gaffiganframe.setvisible(false);         officeframe.setvisible(true);         southframe.setvisible(true);         bigbangframe.setvisible(true);     }  }); louiebutton.addactionlistener(new actionlistener() {     public void actionperformed(actionevent dirtypicked) {         comedystyleanswer = "dirtycomedy";         louieframe.setvisible(false);         gaffiganframe.setvisible(false);         officeframe.setvisible(true);         southframe.setvisible(true);         bigbangframe.setvisible(true);     } }); officebutton.addactionlistener(new actionlistener() {     public void actionperformed(actionevent officepicked) {         comedyshowanswer = "office";         officeframe.setvisible(false);         southframe.setvisible(false);         bigbangframe.setvisible(false);     }  }); southbutton.addactionlistener(new actionlistener() {     public void actionperformed(actionevent southpark) {         comedyshowanswer = "southpark";         officeframe.setvisible(false);         southframe.setvisible(false);         bigbangframe.setvisible(false);     }  }); bigbangbutton.addactionlistener(new actionlistener() {     public void actionperformed(actionevent bigbang) {         comedyshowanswer = "bigbang";         officeframe.setvisible(false);         southframe.setvisible(false);         bigbangframe.setvisible(false);     } }); }  givereccomendation(dramaanswer, comedystyleanswer, comedyshowanswer); }  public static void givereccomendation (string dramaanswer, string comedystyleanswer, string comedyshowanswer) throws ioexception {     system.out.println("public static void started");     jframe personframe = new jframe();     personframe.setcontentpane(new jpanel() {         bufferedimage image = imageio.read(new url("http://images.vcpost.com/data/images/full/29158/person-of-interest-on-cbs.jpg"));         public void paintcomponent(graphics g) {             super.paintcomponent(g);             g.drawimage(image, 0, 0, 1000, 650, this);         }     });     jlabel personlabel = new jlabel("person of interest");     personframe.add(personlabel);     personframe.setdefaultcloseoperation(exit_on_close);     personframe.setsize(1000, 650);     personframe.setvisible(false);     personframe.setlocation(0, 0);     system.out.println("person frame created");      if (dramaanswer.equalsignorecase("fridaynightlights")             && comedystyleanswer.equalsignorecase("clean")             && comedyshowanswer.equalsignorecase("office")) {            personframe.setvisible(true);         system.out.println("person frame set visible");     } } 

}

because placing call giverecommendation in main thread, doing calling method giverecommendation after frame , of listeners set up.

while action listeners correctly in setting value of local strings, perform no other actions.

therefore if want call giverecommendation method, place in 1 of existing action listeners, or create new button , action listener.


Comments