java - AWT Radio Button -


i want change background of frame based on selected radio button. has done using awt. current code change color blue. when clicked on green, nothing changed.

import java.awt.*; import java.awt.event.*;  class extends frame implements itemlistener {     checkbox c1,c2;     checkboxgroup cbg;     a()     {         setlayout(new flowlayout());         cbg= new checkboxgroup();         c1= new checkbox("blue",cbg,false);         c2= new checkbox("green",cbg,true);         this.add(c1);         this.add(c2);         c1.additemlistener(this);         c2.additemlistener(this);     }        public void itemstatechanged(itemevent e)     {         if(e.getstatechange()==itemevent.selected)             this.setbackground(color.blue);         else if(e.getstatechange()==itemevent.selected)             this.setbackground(color.green);         else             this.setbackground(color.black);     }        public static void main(string[] args)     {         a= new a();         a.setsize(500,500);         a.settitle("me");         a.setvisible(true);         a.addwindowlistener(new windowadapter() {               public void windowclosing(windowevent we){system.exit(0);}           });     } } 

the underlying problem (besides th compilation error) condition if , else if identical. might better check source of event , compare either c1 or c2.

note if there should 'black' option, there need third check box.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -