The action listener takes it's action while running time, but static variables and methods will take their value(s) while compile time, so you can define your textfield(s) to some default values.
See this example:
private static int a ;
public static void test(){
a = 3;
System.out.println(a);
a=5;
System.out.println(a);
}
You probably guess the output will be (3 then 5), but actually it's not correct static variables will take the lase value, so the output will be
5
5
That's why they create dynamics as it's value(s) will be change at run time like your okButtonActionPerformed gets the values of textfields after compiling(at run time), but while compiling it's set to null so the output will be
null
You probably have a problem with accessing some classes field(s), see this example :
class Fruit{
private String type;
public String getType(){
return this.type;
}
public void setType(String type){
this.type = type;
}
}
public class Main{
//default constructor
public Main(){
Fruitobj = new Fruit();
obj.setType("Apple");
System.out.println(obj.getType());
}
}
See also this tutorial, and this also a good article answered by StackOverFlow.