0

I'm working on a school project. It's basically a small program that will help people choose best smartphone according to their preferences.

It'll be like, every page will ask a question, then user clicks next and it proceeds to next page.

What would be the best approach for it? I don't want too much code crammed into one file. So I'm thinking -

  1. JFrame using CardLayout.
  2. A separate JPanel for each page.

But I'll want to keep all panels in separate files of their own. Will that be a good idea? If yes, how should I approach going forward in pages? setVisible(true/false) in ActionListener?

Apologies for the noob question, I'm super new to Java and learning on my own.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
satnam
  • 1,457
  • 4
  • 23
  • 43
  • 1
    *"Will that be a good idea?"* - YES. *"how should I approach going forward in pages? SetVisible(True/False) in ActionListener?"* - Don't worry about `setVisible`, simply let `CardLayout` take care of it, but you will need a `next` button of sorts, containing a list of pages in the order you want them displayed – MadProgrammer Sep 23 '13 at 05:21
  • Thanks!!! Can you elaborate a bit on the next button part because thats exactly what I was thinkning – satnam Sep 23 '13 at 19:35

1 Answers1

2

See CardLayoutDemo.java for this simplistic example.

Game view High Scores view

See CardLayoutExample.java for a UI that is closer to what you'd expect for a wizard or survey.

See also how to:

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433