简体   繁体   中英

how can i access the contents of a jframe from other classes?

i'm trying to create a sudoko solver in NetBeans via Java, i created a new project, a package, and in the package i created a Java Class named sudokuCode and a jFrame Form named sudokuGUI. what i'm going to do is when a jButton on jFrame is pressed, sudokuCode catch values from jTextfields (that user entered before), store them in an array, do some calculations on them, and then update jTextfield values with new (actually solved) values, my question is how can i access jTexfield values from inside sudokuCode class and vice versa , is it possible? because they are in same package, or even is it the right way to do these things or am i wrong?

What I usually do is to add a listener to a JTextField that sets a value through the controller when it is finished editing.

Odd that this gets downvoted. I am using principles of MVC, though with the sparse question there isn't much to go on.

First off.

sudokuCode catch values from jTextfields (that user entered before)

You should have an InputMethodListener , when a user changes the values in a text field, the inputmethod listener sets the appropriate values. They should not be stored in your gui class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM