I found an example of how to do a repeating task in java. Now I want that the label's text changes every second. How do I do that? I get the error: non-static method repeatingTask() cannot be referenced from a static context
Somehow the JLabel is not static but public static void main is of course static...
public class whathappens {
StartGUI startGUI = new StartGUI();
public void repeatingTask(){
getJLabel1().setText("Running: "+ new java.util.Date());
}
public static void main(String[] args) {
StartGUI.main(args);
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
repeatingTask();
System.out.println("Running: " + new java.util.Date());
}
}, 0, 1000);
}
}
My idea was to call the method getJLabel1() from startGUI class to change the label within "whathappens" class