Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PASSING PARAMETERS

Status
Not open for further replies.

eh171

Programmer
Feb 21, 2003
9
GB
Right in class1 i have a JTable. When the user selects a row i have done coding to return the value displayed in the selected row (column 0). Class1 coding is as follows:

class1

public static string s1;

class1Constructor(){
tableGUI
insertDataInTable
}

mousepressed(){
row = table.getSelectedRow()
Object ob = table.getValueAt(row,0)
s1 = ob.toString()
}
//end class1

This class works fine. When the user selects a row the coding gets the selected value and each time the user selects a different row the getValue is updated.
However what I want is to display this value in a different class.
class2
String s2

class2Constructor(){
s2 = class1.s1
}
//end class2

Also each time the user selects a different row in class1 the string in s2 should also be updated. class2 coding:


 
I'm not sure what you mean by "However what I want is to display this value in a different class" If you want another class to become aware of the selection I would suggest you adopt the "observer pattern".

I don't want to do the work for you, but if you read this..
it should help.

PS This is a standard approach to "inform" Object B of a change of state to Object A.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top