1

Im building a math testing program for class. A user enters a username, the number of problems, and the number of digits. The program spits out a problem and the user answers in a textfield on that page.

Is there a way to make a default page that loads different JPanels based on a button action? Additionaly, Can you store Jpanels in an arrayList and store the inputs?

ArrayList <JPanel> arrList = new ArrayList<>();

for(int i = 0; actionListener == true ; i++){

    default_JFrame().add(arrList.get(i));
}

Are there any general best practices for Java Swing?

Randy G.
  • 111
  • 7
  • You can swap JPanels easily using a [CardLayout tutorial](http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html). As for storing an `ArrayList`, of course this can be done, but often its better to separate the program's logic from its view, and instead store a List of questions. – Hovercraft Full Of Eels Apr 13 '19 at 22:04
  • `The program spits out a problem and the user answers in a textfield on that page.` - why do you need multiple panels? Just update a JLabel with the text of the new question. – camickr Apr 13 '19 at 22:54
  • @camickr I realized that the longer I tinkered with Java. Its less about updating frames and more about the information on the screen. Thanks for the insight – Randy G. Apr 14 '19 at 21:35

0 Answers0