java - how to use a class in multiple panels -


i'm making tank game. avoid redundancy make buttons in menupanel wrote class button:

package menu;  import java.awt.image; import java.awt.event.actionlistener;  import javax.swing.imageicon; import javax.swing.jbutton;  public class button extends jbutton{      public jbutton button;     public imageicon buttonimage;      public int x, width, height;      public string backgroundpath;     public int y;        public button(string backgroundpath,int x, int y, menupanel menupanel)      {         super();         this.backgroundpath = backgroundpath;         this.x = x;         this.y = y;          buttonimage = new              imageicon(playpanel.class.getresource(backgroundpath));         this.seticon(buttonimage);         this.setbounds(x, y, buttonimage.geticonwidth(),              buttonimage.geticonheight());         this.addactionlistener(menupanel);        } } 

in constructor of method have menupanel menupanelbut want able use code multiple panels quitpanel, highscorepanel, ...etc.

i don't know parameter have use i'm stuck.

thanks in advance!!

change menupanel menupanel parameter actionlistener listener, since reason make easier attach actionlistener it, button doesn't need know menupanel


Comments