java - Button Image Icon Not Showing -




take note newbie.

in programming book "samteachyourself java (in 24 hrs) 7th edition", says on page 252 (just in case if has them right now) can add image icon on button doing did on line 7, 8 , 9. when ran program, buttons showed up, without picture. reason, before added icon, had text on button. when ran icons, text still on button, when removed text icons. need serious help!

package thing; import java.awt.flowlayout; import java.awt.event.actionevent; import java.awt.event.actionlistener; import javax.swing.*; public class thing extends jframe implements actionlistener {     imageicon = new imageicon("desktop\\oof.png");     jbutton firetorpedos = new jbutton(a);     jbutton notorpedos = new jbutton(a);     jbutton reset = new jbutton("reset");     jlabel txt = new jlabel("sir, should fire torpedos?");     jlabel output = new jlabel("");     public void actionperformed(actionevent event) {         string cmd = event.getactioncommand();         switch(cmd) {            case "1":                 notorpedos.setenabled(false);                output.settext("you fired torpedos!");                break;            case "2":                 firetorpedos.setenabled(false);                output.settext("you refuse fire torpedos!");                break;            case "3":                 firetorpedos.setenabled(true);                notorpedos.setenabled(true);                output.settext("you reset program.");                break;          }   }     public thing() {         super("torpedo launcher!!");         setlookandfeel();         setsize(200, 200);         setdefaultcloseoperation(jframe.exit_on_close);         jpanel grid = new jpanel();         boxlayout box = new boxlayout(grid, boxlayout.y_axis);         grid.setlayout(box);         setvisible(true);         flowlayout foo = new flowlayout();         firetorpedos.addactionlistener(this);         notorpedos.addactionlistener(this);         reset.addactionlistener(this);         firetorpedos.setactioncommand("1");         notorpedos.setactioncommand("2");         reset.setactioncommand("3");         grid.add(firetorpedos);         grid.add(notorpedos);         grid.add(reset);         grid.add(txt);         grid.add(output);         add(grid);          }     private void setlookandfeel() {         try {             uimanager.setlookandfeel (                     "com.sun.java.swing.plaf.nimbus.nimbuslookandfeel"             );         } catch (exception exc) {      } }     public static void main(string[] args) {         thing frame = new thing();     }  } 





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -

python - Read npy file directly from S3 StreamingBody -