0

I'm beginner of Java and I have a problem. I have JFrame called chooseMenu that has two buttons. Here is my code for the listeners:

 private void btnNutrisiBahanActionPerformed(java.awt.event.ActionEvent evt) {
    mainPanel = new FoodSourceNutrition();
    mainPanel.repaint();
    mainScrol.setViewportView(mainPanel);
    mainPanel.setAutoscrolls(true);
}

private void btnRekomendasiActionPerformed(java.awt.event.ActionEvent evt) {    
    mainPanel = new Recommendation();
    mainPanel.repaint();
    mainScrol.setViewportView(mainPanel);
    mainPanel.setAutoscrolls(true);
}

Then from FoodSourceNutrition I want to go back to chooseMenu using back button but it seems I can't do this like this:

private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {
    this.dispose();
    chooseMenu cm = new chooseMenu();
    cm.setVisible(true);
}  

How can I open another frame from a frame?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    1) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) But.. **Use a [`CardLayout`](http://download.oracle.com/javase/8/docs/api/java/awt/CardLayout.html) as shown in [this answer](http://stackoverflow.com/a/5786005/418556).** 3) *"so how can i open other jFrame from another jFrame?"* See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Apr 23 '16 at 08:01
  • 1
    Can I suggest that you take the time to learn how to use `CardLayout`, see [How to Use CardLayout](http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html) for more details, and maybe have a look at something like [this example](http://stackoverflow.com/questions/30925564/why-is-my-jlabel-not-showing-up/30926625#30926625) and [this example](http://stackoverflow.com/questions/31602113/listener-placement-adhering-to-the-traditional-non-mediator-mvc-pattern/31604919#31604919) for some clues about how you might be able to use it more efficently – MadProgrammer Apr 23 '16 at 08:43

0 Answers0