Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: radio buttons stop working

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    12
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default radio buttons stop working

    hi,
    I've just noticed a problem while testing my app.
    I have a set of radio buttons that change the text color when it is clicked but noticed they stop working when I click on restart from the Applet menu.
    Could I get some insight into what the problem is?

    thanks


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: radio buttons stop working

    Please post your code.

  3. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    12
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: radio buttons stop working

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.applet.*;
     
    public class Digit extends JApplet implements ItemListener, ActionListener
    {
    	int digit, length;
    	String userIn;
    	ButtonGroup colourGroup;
    	JRadioButton redRB, blueRB, magentaRB, blackRB, greenRB, cyanRB, yellowRB, pinkRB;
    	Color currentColour = Color.black;
     
    	public void init()
    	{
     
    		Container c = getContentPane();
    		c.setLayout(null);
     
    		redRB = new JRadioButton("Red");
    		blueRB = new JRadioButton("Blue");
    		magentaRB = new JRadioButton("Magenta");
    		blackRB = new JRadioButton("Black");
    		greenRB = new JRadioButton("Green");
    		cyanRB = new JRadioButton("Cyan");
    		yellowRB = new JRadioButton("Yellow");
    		pinkRB = new JRadioButton("Pink");
     
    		redRB.setSize(100, 20);
    		blueRB.setSize(100, 20);
    		magentaRB.setSize(100, 20);
    		blackRB.setSize(100, 20);
    		greenRB.setSize(100, 20);
    		cyanRB.setSize(100, 20);
    		yellowRB.setSize(100, 20);
    		pinkRB.setSize(100, 20);
     
    		redRB.setLocation(20, 250);
    		blueRB.setLocation(20, 270);
    		magentaRB.setLocation(20, 290);
    		blackRB.setLocation(20, 310);
    		greenRB.setLocation(130, 250);
    		cyanRB.setLocation(130, 270);
    		yellowRB.setLocation(130, 290);
    		pinkRB.setLocation(130, 310);
     
    		redRB.addItemListener(this);
    		blueRB.addItemListener(this);
    		magentaRB.addItemListener(this);
    		blackRB.addItemListener(this);
    		greenRB.addItemListener(this);
    		cyanRB.addItemListener(this);
    		yellowRB.addItemListener(this);
    		pinkRB.addItemListener(this);
     
    		c.add(redRB);
    		c.add(blueRB);
    		c.add(magentaRB);
    		c.add(blackRB);
    		c.add(greenRB);
    		c.add(cyanRB);
    		c.add(yellowRB);
    		c.add(pinkRB);
     
    		colourGroup = new ButtonGroup();
    		colourGroup.add(redRB);
    		colourGroup.add(blueRB);
    		colourGroup.add(magentaRB);
    		colourGroup.add(blackRB);
    		colourGroup.add(greenRB);
    		colourGroup.add(cyanRB);
    		colourGroup.add(yellowRB);
    		colourGroup.add(pinkRB);
     
     
    	}
     
    	public void paint(Graphics g)
    	{
    		g.setColor(Color.black);
                    g.drawString("hello"[LEFT][/LEFT]);
    	}
     
    		public void itemStateChanged(ItemEvent e)
    	{
    		if(e.getSource() == redRB)
    			currentColour = Color.red;
    		else if(e.getSource() == blueRB)
    				currentColour = Color.blue;
    		else if(e.getSource() == magentaRB)
    				currentColour = Color.magenta;
    		else if(e.getSource() == blackRB)
    				currentColour = Color.black;
    		else if(e.getSource() == greenRB)
    				currentColour = Color.green;
    		else if(e.getSource() == cyanRB)
    				currentColour = Color.cyan;
    		else if(e.getSource() == yellowRB)
    				currentColour = Color.yellow;
    		else if(e.getSource() == pinkRB)
    				currentColour = Color.pink;
     
    		repaint();
    	}
     
     
    }

Similar Threads

  1. Replies: 4
    Last Post: April 27th, 2010, 01:18 AM
  2. JRadio buttons
    By chronoz13 in forum AWT / Java Swing
    Replies: 0
    Last Post: November 29th, 2009, 01:08 AM
  3. Need more buttons!
    By GotWankel? in forum AWT / Java Swing
    Replies: 0
    Last Post: October 5th, 2009, 01:08 AM
  4. [SOLVED] Using html Radio Buttons with Servlets
    By oss_2008 in forum Java Servlet
    Replies: 2
    Last Post: June 25th, 2009, 05:39 AM
  5. Replies: 4
    Last Post: January 27th, 2009, 12:03 AM