java - How can I reference a variable in one JFrame from another JFrame? -


i have jframe buttons , when click 1 of buttons integer decreases 1. trying show integer in jframe when reference error saying non static variable cannot referenced in static context. how can make non static variable?

here code when button clicked.

private void dietpepsibtnactionperformed(java.awt.event.actionevent evt) {                                                  messagelbl.settext("enjoy diet pepsi!");     credit -= 1.00;     stcredit = double.tostring(credit);     creditamt.settext("$" + stcredit);     refresh();     dietpepsi -= 1; 

provide kind accessor in master frame (to allow other components read value) (something getvalue() example).

when ever value changed, fire kind of event. cheat , use propertychange event require not add additional code, or fire change event notifies other frame value has changed.

the second frame use getvalue method read value.

this require second frame have reference master (so can value).

better yet, create model, allow model fire events , share model.

have @ observer pattern more details


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -