jeudi 21 septembre 2017

Adding JMenubar to frame

I use windows builder for eclipse to create menu bar. I can do it in the main Java class. Now I want to create another class namely "ControlMenu", then I call this class to display Menu bar. I tried use the following comment: frm.add(new ControlMenu()) but I get error.

Sample Code:

public class ControlMenu extends MenuBar {
    public ControlMenu(){
    JMenuBar menuBar = new JMenuBar();
    frmRadioButton.setJMenuBar(menuBar);        
    String oplbl = "<html><a style='text-decoration:underline'>O</a>ptions</html>";
    String shapelbl = "<html><a style='text-decoration:underline'>S</a>hape</html>";        
    JMenu smnOptions = new JMenu(oplbl);                
    menuBar.add(smnOptions);
    JMenuItem aboutitm = new JMenuItem("About");
    JMenu  shapeitm = new JMenu (shapelbl); 
    JRadioButtonMenuItem circlesubitm = new JRadioButtonMenuItem("Circle");
    JRadioButtonMenuItem squaresubitm = new JRadioButtonMenuItem("Square");     
    ButtonGroup grpMenueShape = new ButtonGroup();
    grpMenueShape.add(circlesubitm);
    grpMenueShape.add(squaresubitm);        
    shapeitm.add(circlesubitm);
    shapeitm.add(squaresubitm);
    smnOptions.add(aboutitm);
    smnOptions.add(shapeitm);}}

Aucun commentaire:

Enregistrer un commentaire