Skip to content
Advertisement

Java: Is there a more efficient way to write JFrame elements into an array?

This is my first time posting so I apologize if the question is too vague or I do not describe my problem so well.

I am working on a Java JFrame project and have run into a small issue. I need to instantiate arrays of various frame elements. What I have done as of now works, however, it is very inefficient and I was wondering if there is a better, easier way to accomplish this task. The generated code generated by NetBeans instantiates my object as per there variable name that I have supplied. I am then writing a method where I am manually entering the array and which element that is equal to. Here is the auto-generated code:

JavaScript

The same code is used to instantiate five activityEndTxt, 5 dayDropBox, 5 timeStartDropBox and 5 timeEndDropBox instances.

I then write these elements into arrays:

JavaScript

Advertisement

Answer

Use an array as shown below:

JavaScript

Note: I’m not sure the type of dayDropBox0, dayDropBox1 etc. Replace DropBox[] with the applicable type.

Advertisement