am trying to make a menu with a frame en its not working.
and how can i introduce multiple panels in the same frame?
here is my code.
import java.awt.*;
import javax.awt.event.*;
import javax.swing.*;
public class FrameMenu extends Jframe{
private final Color colorValues[]={Color.YELLOW,Color.RED,Color.BLUE,Color.GREEN};
private final Color colorValues2[]={Color.GRAY,Color.CYAN,Color.MAGENTA,Color.WHITE};
private RadioButtonMenuItem colorItems[];//color menu items
public FrameMenu(){
super("MY MENUS");
JMenuBar bar=new JMenuBar();
setJMenuBar(bar);
JMenu musicMenu=JMenu("Music");// create music menu
musicMenu.setMnemonic('M');//set mnemonic to M
bar.add(musicMenu);
JMenu colorMenu=JMenu("Color"); //create color menu
colorMenu.setMnemonic('C');//set mnemonic to O
bar.add(colorMenu);//add colorMenu to Menubar
//array listing string colors
String colors[]={"Yellow","Red","Blue","Green"};
JMenu foregroundMenu=new JMenu("Foregroud");//create foregroundMenu
foregroundMenu.setMnemonic('F');//set Mnemonic to F
foregroundItems=new JRadioButtonMenuItem[colors.length];
foregroundButtonGroup= new ButtonGroup();//manages forground colors
ItemHandler itemHandler=new ItemHandler();//handler for foreground colors
//create forgrond radio button menu items
for(int i=0;i<colors.length;i++){
foregroundItems[i]=new JRadioButtonMenuItem(colors[i]);//create item
foregroundMenu.addd(foregroundItems[i]);//add item to forground menu
foregroundButtonGroup.add(foregroundItems[i]);//add to group
foregroundItems[i].addActionListener(itemHandler);
}//end for loop
foregroundItems[0].setSelected(true);//select first color item
colorMenu.add(foregroundMenu);
colorMenu.addSeparator();
String colors2[]={"Gray","Cyan","Magenta","White"};
JMenu backgroundMenu=new JMenu("Background");//create backgroundMenu
backgroundMenu.setMnemonic('B');//set Mnemonic to B
backgroundItems=new JRadioButtonMenuItem[colors2.length];
backgroundButtonGroup= new ButtonGroup();//manages background colors
ItemHandler itemHandler2=new ItemHandler();//handler for background colors
//create forgrond radio button menu items
for(int i=0;i<colors.length;i++){
backgroundItems[i]=new JRadioButtonMenuItem(colors[i]);//create item
backgroundMenu.addd(backgroundItems[i]);//add item to background menu
backgroundButtonGroup.add(backgroundItems[i]);//add to group
backgroundItems[i].addActionListener(itemHandler2);
}//end for loop
backgroundItems[0].setSelected(true);//select first color item
colorMenu.add(backgroundMenu);
colorMenu.addSeparator();
private class ItemHandler implements ActionListener{
public void actionPerformed(ActionEvent event){
for (int i=0;i<foregroundItems.length;i++){
if(foregroundItems[i].isSelected())
{displayJLabel.setForeground(colorValues[i]);
break;}//end of if
}//end for loop
}//end method actionPerformed
}//end class ItemHandler
private class ItemHandler implements ActionListener{
public void actionPerformed(ActionEvent event2){
for (int i=0;i<backgroundItems.length;i++){
if(backgroundItems[i].isSelected())
{displayJLabel.setBackground(colorValues2[i]);
break;}//end of if
}//end for loop
}//end method actionPerformed
}//end class ItemHandler
//*************************************MENUS*************************************************************************//
JMenu exitMenu=JMenu("Exit");//create exit menu
exitMenu.setMnemonic('x');//set mnemonic to M
bar.add(exitMenu);
exitMenu.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event ){
System.exit(0);//exit application
}//end actionPerformed
}//end inner class
);//end call to addActionListener
}
public static void main(String arg[]){
FrameMenu frameMenu=new FrameMenu();//create FrameMenu
frameMenu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frameMenusetSize(1000,1000);//set frame size
frameMenu.setVisible(true);//display frame
}//end main
}//end FrameMenu