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 5 of 5

Thread: Radio button .. display empty screen ?? plz Help

  1. #1
    Member
    Join Date
    Sep 2011
    Posts
    30
    My Mood
    Nerdy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Radio button .. display empty screen ?? plz Help

    package FunGUI;

    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    import javax.swing.ButtonGroup;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JRadioButton;
    import javax.swing.JTextArea;

    public class RadioButton extends JFrame
    {

    // declare radio buttons.
    private JRadioButton jrbRed, jrbGreen, jrbBlue, jrbWhite;
    JTextArea txaList;

    public static void main (String []args)
    {

    RadioButton gui = new RadioButton();
    gui.setSize(500,250);
    gui.setVisible(true);
    gui.setTitle("Radio Button");
    gui.setLocationRelativeTo(null);
    gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;

    }

    public RadioButton ()
    {

    txaList = new JTextArea(10,20);

    // final JPanel pnlTshirt =
    // new JPanel ( new BorderLayout(100, 200));
    // add(pnlTshirt, BorderLayout.CENTER);


    JPanel pnlRadioButtons = new JPanel ();
    pnlRadioButtons.setLayout(new GridLayout (4, 1));
    pnlRadioButtons.add(jrbRed = new JRadioButton ("Red"));
    pnlRadioButtons.add(jrbGreen = new JRadioButton ("Green"));
    pnlRadioButtons.add(jrbBlue = new JRadioButton ("Blue"));
    pnlRadioButtons.add(jrbWhite= new JRadioButton ("White"));

    // Create a radio button group to group 4 buttons.
    ButtonGroup group = new ButtonGroup ();
    group.add(jrbRed);
    group.add(jrbGreen);
    group.add(jrbBlue);
    group.add(jrbWhite);

    // JPanel pnlNorth = new JPanel (new FlowLayout());
    // pnlNorth.add(group);

    // Set keyboard mnemonics.
    jrbRed.setMnemonic('R');
    jrbGreen.setMnemonic('G');
    jrbBlue.setMnemonic('B');
    jrbWhite.setMnemonic('W');

    //Register listeners for radio button.
    jrbRed.addActionListener(new ActionListener()
    {
    public void actionPerformed (ActionEvent ae)
    {
    txaList.setForeground(Color.red);
    }
    });

    jrbGreen.addActionListener(new ActionListener()
    {
    public void actionPerformed (ActionEvent ae)
    {
    txaList.setForeground(Color.green);
    }
    });

    jrbBlue.addActionListener(new ActionListener()
    {
    public void actionPerformed (ActionEvent ae)
    {
    txaList.setForeground(Color.blue);
    }
    });

    jrbWhite.addActionListener(new ActionListener()
    {
    public void actionPerformed (ActionEvent ae)
    {
    txaList.setForeground(Color.white);
    }
    });

    // Set initial message color to blue.
    jrbWhite.setSelected(true);
    txaList.setForeground(Color.white);

    }


    }
    >

    I was trying to show the button to start handling them .. but nothing show on GUI when its run ??

    I added the panel but is there anything that I could do to fix the problem .. Also, I use to have JPanel instate of JTextArea but I changed it to try another staff ..

    Thanks


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Radio button .. display empty screen ?? plz Help

    Please change the quote tags to code tags to restore the code's formatting. Having all the statements starting in the first column makes the code hard to read.

    A sample:
        int x = 0;
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Sep 2011
    Posts
    30
    My Mood
    Nerdy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Radio button .. display empty screen ?? plz Help

    package FunGUI;
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
    import javax.swing.ButtonGroup;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JRadioButton;
    import javax.swing.JTextArea;
     
    public class RadioButton extends JFrame
    {
     
    	// declare radio buttons.
    	private JRadioButton jrbRed, jrbGreen, jrbBlue, jrbWhite;
    	JTextArea txaList;
     
    	public static void main (String []args)
    	{
     
    		RadioButton gui = new RadioButton();
    		gui.setSize(500,250);
    		gui.setVisible(true);
    		gui.setTitle("Radio Button");
    		gui.setLocationRelativeTo(null);
    		gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
    	}
     
    	public RadioButton ()
    	{
     
    		txaList = new JTextArea(10,20);
     
    //		 final JPanel pnlTshirt =
    //			new JPanel ( new BorderLayout(100, 200));
    //		add(pnlTshirt, BorderLayout.CENTER);
     
     
    		JPanel pnlRadioButtons = new JPanel ();
    		pnlRadioButtons.setLayout(new GridLayout (4, 1));
    		pnlRadioButtons.add(jrbRed = new JRadioButton ("Red"));
    		pnlRadioButtons.add(jrbGreen = new JRadioButton ("Green"));
    		pnlRadioButtons.add(jrbBlue = new JRadioButton ("Blue"));
    		pnlRadioButtons.add(jrbWhite= new JRadioButton ("White"));
     
    		// Create a radio button group to group 4 buttons.
    		ButtonGroup group = new ButtonGroup ();
    		group.add(jrbRed);
    		group.add(jrbGreen);
    		group.add(jrbBlue);
    		group.add(jrbWhite);
     
    //		JPanel pnlNorth = new JPanel (new FlowLayout());
    //		pnlNorth.add(group);
     
    		// Set keyboard mnemonics.
    		jrbRed.setMnemonic('R');
    		jrbGreen.setMnemonic('G');
    		jrbBlue.setMnemonic('B');
    		jrbWhite.setMnemonic('W');
     
    		//Register listeners for radio button.
    		jrbRed.addActionListener(new ActionListener()
    		{
    			public void actionPerformed (ActionEvent ae)
    			{
    				txaList.setForeground(Color.red);
    			}
    		});
     
    		jrbGreen.addActionListener(new ActionListener()
    		{
    			public void actionPerformed (ActionEvent ae)
    			{
    				txaList.setForeground(Color.green);
    			}
    		});
     
    		jrbBlue.addActionListener(new ActionListener()
    		{
    			public void actionPerformed (ActionEvent ae)
    			{
    				txaList.setForeground(Color.blue);
    			}
    		});
     
    		jrbWhite.addActionListener(new ActionListener()
    		{
    			public void actionPerformed (ActionEvent ae)
    			{
    				txaList.setForeground(Color.white);
    			}
    		});
     
    		// Set initial message color to blue.
    		jrbWhite.setSelected(true);
    		txaList.setForeground(Color.white);
     
    	}
     
     
    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Radio button .. display empty screen ?? plz Help

    Where do you add any components to the JFrame so they can be seen?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Sep 2011
    Posts
    30
    My Mood
    Nerdy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Radio button .. display empty screen ?? plz Help

    Quote Originally Posted by Norm View Post
    Where do you add any components to the JFrame so they can be seen?
    Thanks man .. i have been thinking too much and I missed this code of line
    		add(pnlRadioButtons, BorderLayout.NORTH);

    Any recommendation for my program ..
    I am designing a small program for ( T-shirtCompany ) will let the user choose his own style ( out of 3 styles ) colors ( 6 colors ) and size ( all sizes )

    should I design pics and let the user choose the design by ( drop down list ) ? after that choose the color using the same function? each time the user choose one item from the drop list the program will call another pic and show it ?? < in this case I will have around 18 pics
    is this a good idea to start or is there any thing else easier and better?

    thank you guys so much

Similar Threads

  1. Assigning a variable through a radio button selection
    By smarmy_cheauffeur in forum AWT / Java Swing
    Replies: 1
    Last Post: October 17th, 2011, 12:52 PM
  2. Quick beginner radio button question
    By smarmy_cheauffeur in forum AWT / Java Swing
    Replies: 2
    Last Post: October 17th, 2011, 08:20 AM
  3. need help Coding RADIO BUTTON for REMEMBER ME
    By timosoft in forum Java Theory & Questions
    Replies: 3
    Last Post: February 4th, 2011, 05:19 PM
  4. Adding Radio Button Values
    By bazazu in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 13th, 2010, 10:41 AM
  5. Action from Radio Button
    By halfwaygone in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 25th, 2010, 10:52 AM