I have a CommonTableModel class that has several instance methods, and each of them works with two instance variables
Now I have six tables, each of which has diff. column names, but must have all the instance methods of the CommonTableModel class. Therefore, in order to pass an instance of CommonTableModel to a JTable instance, I must first initialize both instance variables (columnNames and data).
Q1. Should I make six tabular models, each of which corresponds to each table, and then extends them to CommonTableModel?
public class FirstTableModel extends CommonTableModel { public FirstTableModel() { columnNames = {"id", "name"}; data = {{1, "John"}}; } }
In the above example, I tried to initialize the inherited data elements so that each of the six table models could fill in the column names according to the table that they designate.
But I have a bug that limits me to initializing the inherited members in this way. I think we cannot initialize instance variables this way.
Then how can I populate the instace variables for the CommonTableModel so that the methods of the CommonTableModel instance process the data that I populate them later.
One solution is to pass the data in the CommonTableModel constructor, but this way I have to pass all the column names every time I create a table.
I am very confused because I do not have much experience in programming and do not know good coding methods.
Please also name some good model template books so I can better understand design templates.
source share