reference - Java - double menuBar - set 'static' and 'void' parametr -


problem with:

  1. paintui() becouse cannot make static reference non-static method paintui() type gui
  2. exitb.addactionlistener.

the method addactionlistener(actionlistener) in type abstractbutton not applicable arguments (new actionlistener(){})

how can fix that?

//imports..  public class gui extends jframe  {    public gui() {      paintui();     }      public final void paintui()      {         createtoolbars();            jframe f=new jframe();         //setting of 'f' ...       }        private void createtoolbars() {          jtoolbar toolbar1 = new jtoolbar();         jtoolbar toolbar2 = new jtoolbar();          imageicon newi = new imageicon("new.png");         //another next icons..          jbutton newb = new jbutton(newi);         // next jbuttons          toolbar1.add(newb); 

here problem exitb.addactionlistener becouse..: multiple markers @ line - actionlistener cannot resolved type - method addactionlistener(actionlistener) in type abstractbutton not applicable arguments (new actionlistener(){})

        exitb.addactionlistener(new actionlistener() {              public void actionperformed(actionevent event) {                 system.exit(0);             }          });         createlayout(toolbar1, toolbar2);       }      private void createlayout(jcomponent... arg) {          container pane = getcontentpane();         //some creating....          gl.sethorizontalgroup(gl.createparallelgroup()                 .addcomponent(arg[0], grouplayout.default_size,                   grouplayout.default_size, short.max_value)                 .addcomponent(arg[1], grouplayout.default_size,                   grouplayout.default_size, short.max_value)         );          gl.setverticalgroup(gl.createsequentialgroup()                 .addcomponent(arg[0])                 .addcomponent(arg[1])         );     }      public static void main(string[] args)      {          swingutilities.invokelater(new runnable() {             public void run() { 

/** here problem reference of "paintui()" becouse: cannot make static reference non-static method paintui() type gui */

                paintui();              }         });     }   } } 

paintui();//here problem reference 

you have not created instance of gui class can't invoke method of class.

instead should use:

new gui(); 

you don't need invoke paintui() because constructor of gui class you.

as other answer shows above statement should invoked within swingutilities.invokelater() because gui components should created on event dispatch thread (edt). read section swing tutorial on concurrency. important concept understand.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -