title: How to change 'card' in Jframe cardlayout from Jpanel which belonging to card and its placed in another class?
body: <p>I have written a jframe with cardlayout as in the following code :</p>
  
  <pre><code>public class Gui extends JFrame {
  
  
  private static CardLayout cardlayout = new CardLayout();
     private static JPanel cards = new JPanel(cardlayout);
  
  public Gui() {
  
  cards.setLayout(cardlayout);
  CasaPanel card =new CasaPanel();
  cards.add(card,"casa");
  InCash card_1 = new InCash();
  cards.add(card_1,"in");
  OutCash card_2 = new OutCash();
  cards.add(card_2,"out");
  setLayout(new BorderLayout());
  add(cards, BorderLayout.CENTER);
  
  }
  
  public static void showCard(String name)
  {
      cardlayout.show(cards, name);
  }
  </code></pre>
  
  <p>i'm trying to call method to change card (ShowCard) from one of the JPanel(CasaPanel) , which is itself a 'card'. I want change a 'card' after clicking a button in a JPanel(CasaPanel) which is in another class. How to do this?I mean i know how to add button and listener but i don't know if is it possible to call a method in JFrame from a Jpanel class belonging to that frame ? How to refer to method in JFrame from  other classes? I looked at  <a href="http:////stackoverflow.com/questions/13913473/i-cant-change-card-in-cardlayout-using-jtree-listener" rel="nofollow" title="this">this</a> question but i really don't want  put all code in one class.</p>