First I would like to say that I have only worked with java for 1 month now. This is probly a pretty simple question. I searched and the classic fruit example did not make any sense to me. I spent hours looking at it and trying to figure out how to apply this to make it work. It does not make any sense to me because everyone explains how to get and set a property with 2 lines of code and no structure statements. I would really appreciate a breakdown in how to talk to non-static from static.
I would like to setText in text box in my OBD2nerForm class from a separate and static class.
public class OBD2nerForm extends java.awt.Frame {
/** Creates new form OBD2nerForm */
public OBD2nerForm() {
initComponents();
} ....................................
public String setText(String text){
this.jFormattedTextField1.setText(text);
}
I think I have a static reference to this instance of the form defined here..
public class Status {
public static OBD2nerForm form = new OBD2nerForm();
it is called from my main like this
public class obd2ner {
public static void main(String[] args) throws IOException {
Status.form.main(args);
Then when I try to call it.. Status.form.getText gives me the initial values when the form is created. When I setText, it does not change the one on the screen.
I am just displaying this to keep it simple. There are many other parts going on. I have a static monitor on a serial port and I want it to grab the next data to be sent from the text box and then increment it.
I just don't understand how to use a getter and a setter on a non-static. It's not quite doing what I need it to do. It seems like I am seeing one instance on my screen and it is using a new instance to perform the getting and setting.
I tried this as per an answer I received, but it did not work...
public class OBD2nerForm extends java.awt.Frame {
String X = "";
//Trying out the runnable method of incrementing the code public String getNewScannerValueRunnable(){
Runnable doWorkRunnable = new Runnable() {
@Override
public void run() {
Status.form.getNewRotatingValue()
;}
};
SwingUtilities.invokeAndWait(doWorkRunnable);
return X;
}
I could really use some other suggestions. i just don't understand what has to happen here.