In my program, there is a MainFrame (just a JFrame) and a MainView (just a JPanel). In the timer-section you can see, that I want to remove the panel from the frame on editing the file, but nothing happens. The panel just stays on the frame and doesn't disappear.
public class MainClass {
private static String gesture;
private static MainFrame mainFrame;
private static MainView mainView;
public static void main(String[] args) {
mainFrame = new MainFrame();
mainFrame.setVisible(false);
mainView = new MainView();
mainFrame.add(mainView);
mainFrame.setVisible(true);
Timer gestureControl = new Timer();
gestureControl.schedule(new TimerTask() {
public void run() {
String gestureNew = Filereader.getLines("/Users/alexanderjeitler-stehr/Desktop/widget.txt")[0];
if(!gestureNew.equals(gesture)) {
gesture = gestureNew;
System.out.println(gesture);
if(gesture.equals("1")) {
mainFrame.getContentPane().remove(mainView);
mainFrame.invalidate();
mainFrame.validate();
}
}
}
}, 0, 1000);
}
}