I have created 2 menus using JForms.

I have two buttons in the 1st menu (menu1.java)

I want to go to the second menu (GUI of menu2.java) whenever I press button 1 in menu1.java.

How can I do that. What should I write in the actionListener func for button1?

i'll say that the best method is to add menu2 to menu1 just like you will add a button to a menu Example:

import javax.swing.*;

public class MenuTestFrame extends JFrame{
public MenuTestFrame(){
setSize(300, 300);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JMenuBar theBar = new JMenuBar();
setJMenuBar(theBar);

JMenu menu1 = new JMenu("Menu1");
JMenu menu2 = new JMenu("Menu2");
menu2.add(new JMenuItem("Item1"));
menu2.add(new JMenuItem("Item2"));

menu1.add(menu2);
menu1.add(new JMenuItem("AnItem"));
theBar.add(menu1);          
}

public static void main(String[] args){
new MenuTestFrame().setVisible(true);
}
}

One of my friends gave me another method....change the main method of 2nd menu to some normal function.
Call this function in the actionListener event for the button for which you want to call this 2nd menu in the 1st menu. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.