Q:

Editing JLabel text from another class

So what I am trying to do is to edit text of my JLabel from another class. I do it with label.setText("bla bla"); but it doesn't affect my JLabel.
My code in GUI class lookes something like this:
public class GUI {

    JFrame f1 = new JFrame("GUI");
    JLabel l1 = new JLabel("Output");
    JTextField tf1 = new JTextField("");

    public run(){  // main calls this method.

    Listener listener = new Listener();

    f1.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    f1.setBounds(450, 170, 400, 400);
    f1.setVisible(true);
    f1.setResizable(false);
    f1.setLayout(null);

    l1.setBounds(8, 8, 200, 30);
    listener.listen(tf1);

    f1.add(l1);
    }
}

and then i have this listener class that is supposed to make changes to JLabel depending on user input. Here is the code:
public class Listener {

    GUI gui = new GUI();

    public void listen(final JTextField textfield) {

        textfield.getDocument().addDocumentListener(new DocumentListener() {

            public void changedUpdate(DocumentEvent e) {
                test();
            }

            public void removeUpdate(DocumentEvent e) {
                test();
            }

            public void insertUpdate(DocumentEvent e) {
                test();
            }

            public void test() {
                if (gui.everythingOK()) { // everythingOK is just a boolean that test if input is valid number and returns true if it is.
                    gui.l1.setText("No errors."); // this code is supposed to change JLabels text.
                } else {
                    gui.l1.setText("Error."); // this code is supposed to change JLabels text.
                }
            }
        });
    }
}

Method everythingOK works perfectly, you just have to trust me on that one. It works if I define JLabel as static, but it only works first time. After first change no more changes appear in JLabel, so defining it static isn't helping me. I hope there is someone who knows what is wrong with this code. And don't mind if there is obvious mistakes, because I only took the most important parts of very very long code. 
Thanks in advance.
Here is my everythingOK code:
public boolean everythingOK() {
        if (hasInt(tf1) && isValid(tf1)) {
            return true;
        } else {
            return false;
        }
    }

    public boolean hasInt(JTextField textfield) {
        try {
            Integer.parseInt(textfield.getText());
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    }

    public boolean isValid(JTextField textfield) {
        if (hasInt(textfield)) {
            if (Integer.parseInt(textfield.getText()) >= minValue && Integer.parseInt(textfield.getText()) <= maxValue) {
                return true;
            } else {
                return false;
            }

        } else {
            return false;
        }

    }

A:

Your Listener class creates another instance of Gui.
GUI gui = new GUI();

The code in Listener.test() changes the l1 label in it's Gui instance and not in the Gui that is displayed.
You have to give the Listener a reference to the real Gui object.
You might also have to wrap the code that sets the new label in SwingUtilities.invokeLater, so that it is executed from the event dispatching thread.
SwingUtilities.invokeLater(new Runnable() {
    public void run() {
      <guiInstance>.l1.setText("Query: " + queryNo);
    }
  });

UPDATE:
Here is sample code that does what you want. You can take it as is and play with it. Look at how the GUI class gives it's own instance to Listener when it creates it (new Listener(this). If the text field contains text then the label prints "No errors", otherwise in prints "Error".
The SwingUtilities.invokeLater part is not really necessary in this case. But if you develop your program further and start to add background threads which want to update UI then you need to do it this way. Just a warning for later... ;-)
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.*;

public class GUI {

    JFrame f1 = new JFrame("GUI");
    JLabel l1 = new JLabel("Output");
    JTextField tf1 = new JTextField("");

    public void run(){  // main calls this method.
        f1.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        f1.setBounds(450, 170, 400, 400);
        f1.setVisible(true);
        f1.setResizable(false);
        f1.setLayout(new GridLayout(2,1));

        f1.add(l1);
        f1.add(tf1);

        f1.pack();

        Listener listener = new Listener(this);
        listener.listen(tf1);
    }

    public static void main(String[] args) {
        new GUI().run();
    }

    public boolean everythingOK() {
        return tf1.getText().length() > 0;
    }

    class Listener {
        private GUI gui;

        public Listener(GUI gui) {
            this.gui = gui;
        }

        public void listen(final JTextField textfield) {

            textfield.getDocument().addDocumentListener(new DocumentListener() {

                public void changedUpdate(DocumentEvent e) { test(); }
                public void removeUpdate(DocumentEvent e) { test(); }
                public void insertUpdate(DocumentEvent e) { test(); }

                public void test() {
                    SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            if (gui.everythingOK()) { // everythingOK is just a boolean that test if input is valid number and returns true if it is.
                                gui.l1.setText("No errors."); // this code is supposed to change JLabels text.
                            } else {
                                gui.l1.setText("Error."); // this code is supposed to change JLabels text.
                            }
                        }
                    });
                }
            });
        }
    }
}

