Not really sure how to phrase the question. Essentially my issue is this:
I have a Form that when the user clicks a button, it invokes a JFrame that populates a datatable with a sql query. The datable frame also has a button. The user can select a cell in the frame and then press the "Select" button. What I need to have happen is to somehow populate a text field with a value from the selection on the parent form. The datatable is invoked from a method in my Main Form class. There is an action event listener associated with the button on the datatable form. Provided is the code from Main:
private void MTHSelectAlertTypeActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
showPreviousAlertTypes();
}
private void showPreviousAlertTypes()
{
String query = "select distinct dc_alert_type_id from custom_alert order by dc_alert_type_id";
String labels [] = {"Alert Type", "Select" };
ArrayList selections = new ArrayList();
JFrame frame = new JFrame("Existing Alert Types ");
//DataTable is a class I defined based on the Sun Tutorial on how to create Swing Tables. It is pretty robust and I am happy with it.
DataTable existingAlertTypesTable = new DataTable(query, labels, conn, "Existing Alert Types", "Selections", true, frame);
//Draw and render the frame:
existingAlertTypesTable.setOpaque(true);
frame.setContentPane(existingAlertTypesTable);
frame.pack();
frame.setVisible(
}
So that's the calling function from Main. I have a public action event associated with my button. All of the values passed in to the constructor are necessary to render my table with the required data:
query is fairly obvious, conn is my database connection object (instantiated globally on the form), The next string is the title of the form, The string "Selections" is a descriptor that I use to differentiate which action I want performed on which table. (I have other buttons on this form that display different data and I have other actions associated with them), The boolean tells the renderer that I want checkboxes displayed on the table, and the frame is the actual table. I pass this in so I can refresh the table from a public method.
So the table is displayed with the requisite data. The user can select cells in the table that populate an array. When they press the "Select" button, I want to pass that array back to the caller, and then set a value from that array in a Text field on the parent frame. Here is the acton Event in the DataTable class:
public void actionPerformed(ActionEvent event) {
String command = event.getActionCommand();
// A button (with an action listener) has been rendered on the DataTable frame object. When the user clicks on it, this ActionEvent fires
if ("Select" == command)
{
if (selection_array.size() <= 1)
{
//selection_array is populated with selections from the dataframe. The user hasn't selected anything. I display a JOption pane admonishing them for their ineptitude
}
/*I have populated an array of values with the selections already. I need to pass this back to main now. I figure I need some type of event listener in the function that instantiated this object that is invoked here. The end result is to populate a text frame with a value from this array (to be determined in the main frame.) */
}
}
So that's the long and short of it. Let me know if you need any additional data or requirements. I'm still trying to wrap my head around events