Reputation: 31
This is pretty elementary but I do not even know how to search anything for what I need. I have created a system that has a few classes and two projects that communicate with each other via sockets.
Now I am aiming to create a GUI for the system using a designer Netbeans has but I am kind of stuck in limbo when it comes to communicating the GUI with the rest of the classes.
JTextField.setText("PleaseHelp");
in the run method of the GUI I get an error saying : non-static variable JTextField cannot be referenced from a static context.I know I'm not asking for something specific but I have no clue on how to search for what I need. All I get is tutorials on how to make simple calculator GUIs which is easy to be done because there is only one class, the JFrame
.
Upvotes: 3
Views: 1978
Reputation: 481
JTextField
is a class and setText
is not static. You need to reference the JTextField
that you want to change.Basically, it should look something like this:
GUI gui = new GUI(/*Parameters*/);
gui.getTextField().setText("PleaseHelp");
Where getTextField
is a method of the GUI class (add this to the class created by the Netbeans GUI designer):
public JTextField getTextField(){
return /*TODO: Enter text field name here*/;
}
Upvotes: 3