0

I'm new to Java and programming. I want to generate an int in a JDialog class by selecting a row in a table and send that int to the main class which created it, or, to handle the button action performed in the main class. Main class creates the subclass here:

private void launchtable() {
    DlgBeds dcl = new DlgBeds();
    dcl.setLocationRelativeTo(this);
    dcl.setVisible(true);

    // I want in this place to put something like this:
    txtCode.setText(subclassgeneratedint );
}

But first I need to get that int from the subclass., I tried creating a method there that I can use in main to return the int, but it instead sets the text with the first row selected (the default selection), and it can't return more row selections to keep changing txtCode; the method like just dies there. The main could also have an action performed for the button in the subclass but the parameter would need to be one from the subclass I guess.

protected void actionPerformed[button in the subclass](ActionEvent e) {
    //actions
}

I'm really lost, I know I need to study more to solve situations like this but I needed the answer as fast as possible.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
gluten
  • 1
  • 3

1 Answers1

1

Add a ListSelectionListener to your table. You can get the selected row as shown here and pass it to your main window using a PropertyChangeListener as shown here and here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045