Reputation: 1
I am trying to make a program to do calculations of doubling time based on multiple readings at different points in time.
I am using a Netbeans JFrame
with a JTextfield
and a DateChooser
with an add button. I intend to add the values in the JTextfield
and the DateChooser
to a two dimensional array of the data type [Date,double] each time the add button is clicked.
Once all the data is entered I have another button that then plots a graph based on these data points and calculates the doubling time and generates a report.
I am facing the following problems.
I will not know the number of elements I will have it can be 2 it can be 20 it will depend on the observations, I am unsure of how I can set this up in the context of a JTextField
, JButton
and DateChooser
Any help will be appreciated.
Upvotes: 0
Views: 185
Reputation: 1
You can have complex user type object with 2 fields and then have array of that object.
Upvotes: 0
Reputation: 347314
I will not know the number of elements I will have it can be 2 it can be 20 it will depend on the observations, I am unsure of how I can set this up in the context of a JTextField, JButton and DateChooser
I wouldn't. It would be eaiser to manage with a JTable
.
This way you won't need to care how many observations need to be made, they can simply keep adding new rows as they want.
I would also make a simple Object that contains the Date
and double
value, maybe called Observation
, which can then simply be managed by the JTable
's model and if required, transferred to something like a List
or array.
This links the Date
and value together in a obvious manner which is not easily disconnected - IMHO
Upvotes: 1
Reputation: 180
Instead of using an Array, use a List. That way you can use List.add()
and you don't need to worry about how many elements are going to be in that list.
Elements in a list can be access similar to an array by using List.get(index)
to get the objects or a more generic for( element : List ) {}
.
Upvotes: 0