Eike Peters
Eike Peters

Reputation: 1

JButton action in other class

I have a main Frame with two panels:

JPanel Menu = new Menu();
Menu.setBounds(0, 37, 300, 644);
contentPane.add(Menu);
Menu.setVisible(false);

JPanel Fahrtenbearbeiten = new Fahrtenbearbeiten();
Fahrtenbearbeiten.setBounds(0, 0, 1422, 668);
contentPane.add(Fahrtenbearbeiten); 

In the Menu panel, I want to make a button, who sets the Fahrtenbearbeiten panel's Visible(false). The Problem is: How can I reach an action which is triggered in the Menu panel (Menu.java) and has an action in an other file (Haupt.java)?

Upvotes: 0

Views: 49

Answers (1)

Yannick
Yannick

Reputation: 843

  1. Declare the Fahrtenbearbeiten JPanel as global variable

    private JPanel fahrtenbearbeitenPnl = new JPanel();
    
  2. Create a method

    public void hideFahrtenbearbeitenPnl()
    {
       fahrtenbearbeitenPnl.setVisible(false);
    }
    
  3. Call this method on the object of the class which contains the panel. For example:

    menu.hideFahrtenbearbeitenPnl();
    

Let me know if I've got your question wrong. (Maybe post the whole class(es) for easier support)

Upvotes: 2

Related Questions