954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Working with JApplet with Menus. a little help please :)

Im having problems with my code. :(
the code should. the submenu for my menu should be on a radio button type.
here's my first code:

public ... { 
//for background
   JMenuItem image = new JMenuItem("Images");
    JMenuItem music = new JMenuItem("Music");
    //submenu of music
    JRadioButtonMenuItem play = new JRadioButtonMenuItem("Play");
    JRadioButtonMenuItem loop = new JRadioButtonMenuItem("Loop");
    JRadioButtonMenuItem stop = new JRadioButtonMenuItem("Stop");
    ButtonGroup group = new ButtonGroup();
}


public void init(){
    	con.setLayout(new FlowLayout());
		setJMenuBar(mainBar);
		mainBar.add(menu1);
		mainBar.add(menu2);
		mainBar.add(menu3);
		menu1.add(open);
		menu1.add(save);
		menu1.add(reset);
		menu2.add(setFont);
		menu2.add(setColor);
		menu3.add(image);
		menu3.add(music);
		music.add(play);
		music.add(loop);
		music.add(stop);
}

when i try to run it. the Music menu doesnt appear. it will changed to Play(radiobutton)
does the button group will help? when i tried to use the button group nothing happens :(

Thanks :)

LittleMissChoco
Newbie Poster
11 posts since Sep 2011
Reputation Points: 10
Solved Threads: 1
 

add JRadioButtonMenuItem to the ButtonGroup, then only one JRadioButton from ButtonGroup could be selected

mKorbel
Veteran Poster
1,141 posts since Feb 2011
Reputation Points: 480
Solved Threads: 224
 

like this??::

group.add(play);

LittleMissChoco
Newbie Poster
11 posts since Sep 2011
Reputation Points: 10
Solved Threads: 1
 

exactly :-)

mKorbel
Veteran Poster
1,141 posts since Feb 2011
Reputation Points: 480
Solved Threads: 224
 

it doesnt work. i've tried that already :(

LittleMissChoco
Newbie Poster
11 posts since Sep 2011
Reputation Points: 10
Solved Threads: 1
 

the Music menu will not appear. it will be changed to the Play radio submenu :(

LittleMissChoco
Newbie Poster
11 posts since Sep 2011
Reputation Points: 10
Solved Threads: 1
 

got it :) add group and then the music menu :)

LittleMissChoco
Newbie Poster
11 posts since Sep 2011
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: