This is a MenuBar class which is supposed to assemble a Menu bar.. basically i have some JMenus which contains some JMenu items here... and add all the JMenus to this class which is the bar (sorry if this is confusing)
i am trying to write a public method to remove or better making one of the MenuItem "unclickable" (which built-in function should i use??) ... ok, i was on the JFrame class outside this class trying to access the public methods in this class but seems the public methods are not reachable.
last thing to do to complete my project (hopefully)... i appreciate all the inputs =)
import javax.swing.*;
import java.awt.event.*;
import java.awt.print.*;
/*
* This is purely GUI component
* This is a MenuBar class with components added to it
*/
public class MenuBar extends JMenuBar
{
private JFrame frame;
private JMenu menuFile, menuEdit, menuHelp;
private JMenuItem closeMenuItem, printMenuItem, showTableMItem, addRecordMItem, searchMItem, updateMItem, deleteMItem, insMItem, adMItem;
public MenuBar(JFrame theFrame)
{
///////////////////// file //////////////////////////////
this.frame = theFrame;
menuFile = new JMenu("File"); // menu file
menuFile.setForeground(java.awt.Color.black);
showTableMItem = new JMenuItem("Show Table"); // showTable item
menuFile.add(showTableMItem); // menu edit with showTable item
showTableMItem.addActionListener(new ShowTable(frame));
closeMenuItem = new JMenuItem("Close"); // menu closeItem
closeMenuItem.setAccelerator(KeyStroke.getKeyStroke('q', java.awt.Event.CTRL_MASK, false));
closeMenuItem.addActionListener(new closeMenuHandler());
//printMenuItem = new JMenuItem("Print"); // menu printItem
//menuFile.add(printMenuItem); // menu file with printItem
//printMenuItem.setAccelerator(KeyStroke.getKeyStroke('p', java.awt.Event.CTRL_MASK, false));
////////////// ActionListener /////////////
menuFile.add(closeMenuItem); // menu file with closeItem
//////////// Menu Bar Edit items /////////////////
menuEdit= new JMenu("Edit"); // menu edit
menuEdit.setForeground(java.awt.Color.black);
addRecordMItem = new JMenuItem("Add a Record"); // addRecord item
menuEdit.add(addRecordMItem); // edit menu with addRecord item
addRecordMItem.addActionListener(new AddRecord(frame));
searchMItem = new JMenuItem("Search Record");
menuEdit.add(searchMItem);
searchMItem.addActionListener(new Search(frame));
/*
updateMItem = new JMenuItem("Update Record");
menuEdit.add(updateMItem);
updateMItem.addActionListener(new Update(frame));
*/
deleteMItem = new JMenuItem("Delete Record");
menuEdit.add(deleteMItem);
deleteMItem.addActionListener(new Delete(frame));
adMItem = new JMenuItem("Advanced SQL Access");
menuEdit.add(adMItem);
adMItem.addActionListener(new Advance(frame));
///////////////////////////////////////
menuHelp = new JMenu("Help");
menuHelp.setForeground(java.awt.Color.black);
insMItem = new JMenuItem("Read me");
insMItem.addActionListener(new Instruction());
menuHelp.add(insMItem);
//////// Add all menu things to the menu bar /////////
//menuBar = new JMenuBar(); // menu bar
setBackground(java.awt.Color.gray);
add(menuFile); // menu bar with menu file
add(menuEdit); // menu bar with menu edit
add(menuHelp);
frame.add(this);
}// end Constructor
[B] /// NOT reachable [/B]
public JMenuItem getAdvance()
{
return adMItem;
}
[B] /// NOT reachable [/B]
public void removeAdSQL()
{
this.remove(adMItem);
}
}
class closeMenuHandler implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
System.exit(0);
}
}