java - JRadioButton Input not responding -


i'm new java, , programming in general.i trying exercise create radio buttons change background colour when selected.at moment using eclipse ide.

eclipse not giving me errors , can run b/m program fine, radiobuttons showing , being clickable.however, radio buttons fail change background colour when select them. appreciate answers , pointers can get.

thanks!

    import java.awt.*;     import java.awt.event.*;     import javax.swing.*;     import javax.swing.event.*;       public class gui{     //declares variables     jradiobutton red=new jradiobutton("red");     jradiobutton blue=new jradiobutton("blue");     jradiobutton yellow=new jradiobutton("yellow");     buttongroup group = new buttongroup();     //constructor     public gui(){         //sets title         super("radiobutton exercise");         //sets layout default         setlayout(new flowlayout());         //adds jradiobuttons         add(red);         add(blue);         add(yellow);         //groups variables         group.add(red);         group.add(blue);         group.add(yellow);         //creates handlerclass object         handlerclass handler = new handlerclass();         //when buttons clicked, handlerclass called         red.additemlistener(handler);         blue.additemlistener(handler);         yellow.additemlistener(handler);       }      public class handlerclass implements itemlistener{         public void itemstatechanged(itemevent x){             if(x.getsource()==red){                 setbackground(color.red);             }             else if(x.getsource()==blue){                 setbackground(color.blue);             }             else{                 setbackground(color.yellow);             }         }     }        } 

assuming meant

public class gui extends jframe { 

it's not jradiobutton not responding, problem setbackground being called on frame directly, rather it's visible component, i.e. contentpane. can use:

getcontentpane().setbackground(color.red); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -