aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Adding JMenuBar, after user Authentication.. Please Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Adding JMenuBar, after user Authentication.. Please Help" Watch "Adding JMenuBar, after user Authentication.. Please Help" New topic
Author

Adding JMenuBar, after user Authentication.. Please Help

ghazanfar khan
Ranch Hand

Joined: Apr 18, 2005
Posts: 81
Hello,
I have JFrame in which i m opening first internal frame for taking input from user for validation of email and passwrod. Then with respect to assign role base, i am trying to add JMenuBar on this frame. But it is not adding, it validate user email and password from DB but does not show any JMenuBar on this frame it remain unchange.

Can anyone please help me out i need help no one also replied me for my previous asked question..........IT IS VERY URGENT



public class MainFrame extends JFrame implements ActionListener {
JDesktopPane desktop;
JPanel login = new JPanel(new GridLayout(0, 2));
JLabel email = new JLabel("Email:");
JLabel password = new JLabel("Password:");
JTextField emailTxt = new JTextField();
JTextField passwordTxt = new JTextField();
JButton loginbut = new JButton("Login");
JButton forgotpass = new JButton("Forgot Password");


public MainFrame() {
super("something ");
desktop = new JDesktopPane(); //a specialized layered pane
loginbut.addActionListener(this);
createLoginForm()();
setContentPane(desktop);
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
}


public void createLoginForm() {
login.add(email);
login.add(emailTxt);
login.add(password);
login.add(passwordTxt);
login.add(loginbut);
login.add(forgotpass);
JInternalFrame frame = new JInternalFrame();
frame.getContentPane().add(login);
frame.setSize(260, 100);
frame.setLocation(100, 100);
frame.setVisible(true); //necessary as of 1.3
desktop.add(frame);
try {
frame.setSelected(true);
} catch (java.beans.PropertyVetoException e) {}

}



protected JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar();

//Set up the lone menu.
JMenu menu = new JMenu("Open");
menu.setMnemonic(KeyEvent.VK_O);
menuBar.add(menu);

JMenu menu1 = new JMenu("Query");
menu1.setMnemonic(KeyEvent.VK_Q);
menuBar.add(menu1);

//Set up the first menu item.
JMenuItem menuItem = new JMenuItem("New Request");
menuItem.setMnemonic(KeyEvent.VK_N);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_N, ActionEvent.ALT_MASK));
menuItem.setActionCommand("new");
menuItem.addActionListener(this);
menu.add(menuItem);

//Set up the second menu item.
menuItem = new JMenuItem("Quit");
menuItem.setMnemonic(KeyEvent.VK_Q);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_Q, ActionEvent.ALT_MASK));
menuItem.setActionCommand("quit");
menuItem.addActionListener(this);
menu.add(menuItem);

JMenuItem menuItem1 = new JMenuItem("All");
menuItem1.setMnemonic(KeyEvent.VK_A);
menuItem1.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_A, ActionEvent.ALT_MASK));
menuItem1.setActionCommand("All");
menuItem1.addActionListener(this);
menu1.add(menuItem1);


return menuBar;

}



public void actionPerformed(ActionEvent e) {

if(e.getSource()== loginbut){
PasswordEncrypt pwd = new PasswordEncrypt();
String pWD = pwd.encrypt((String)passwordTxt.getText());
String email = (String)emailTxt.getText();
UserDB user = new UserDB();
if(user.getObj(email, pWD) ){
this.setJMenuBar(createMenuBar());
this.getJMenuBar();
repaint();
}

}

}






//Quit the application.
protected void quit() {
System.exit(0);
}

/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);

//Create and set up the window.
MainFrame frame = new MainFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Display the window.
frame.setVisible(true);
}

public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
this.setJMenuBar(createMenuBar());
validate();//<-----------------------
//this.getJMenuBar();//<-??
repaint();
}
ghazanfar khan
Ranch Hand

Joined: Apr 18, 2005
Posts: 81
Thanks Michael for your reply
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding JMenuBar, after user Authentication.. Please Help