Carye James Carye James - 6 months ago 16
Java Question

Calling main form from another form JavaNetbeans

Hi guys I'm new here so please bear with me..

I have two jframe forms. The main form which is Talaan and the second jframe form which is AddRecord..

The main Talaan is to populate data in Table from the database with method

checkDB()
.

Now my problem is when i call the second form AddRecord which is used for adding records, I want to call checkDB() method from Talaan to refresh the table to repopulate the data.. What code should I add..

I tried the codes below which does not work..

Talaan populate = new Talaan();
populate.checkDB();


Can you help me?

Answer

The main form which is Talaan and the second jframe form which is AddRecord..

An application should only have a single JFrame. The second window should be a modal JDialog.

when i call the second form AddRecord which is used for adding records

When you click the "Add Record" button on the dialog you need to add the data from the dialog to the DefaultTableModel of the JTable.

So the easiest way to do this is to pass the DefaultTableModel as a parameter to your "AddRecord" class. then you can just use the addRow(...) method of the DefaultTableModel to add the data to the table.

Or, if you want to reread all the data from the database again, then your method to get the data from the database should return a TableModel object. Then you can just update the JTable using:

table.setModel( theUpdatedTableModel );

Your question is way to vague to give a specific answer.

Edit:

how do I call checkDB() method from AddRecord..

The checkDB method belongs to the Taalan class. So you need to pass the Taalan class as a parameter to the AddRecord class.

This is basic Java. If you want to invoke a method on a class then you need to have a reference to the class.

Comments