Reading files with code value pairs
Make a Map like this

Map&lt;String, JTextField&gt; map = new HashMap&lt;&gt;();
map.put("$codeA", panel1.txtFieldA);
map.put("$codeB", panel2.txtFieldB);


and change your loop like this

String code = null;
while ((code = br.readLine()) != null) {
    JTextField jtf = map.get(code);
    if (jtf != null)
        jtf.setText(br.readLine());
    else
        br.readLine();
}