Veröffentlicht 22. September 200816 j Hallo COM. Ich habe ein kleines Problem mit meinem Java-Programm. Und zwar teste ich gerade, wie es am besten umsetze, mein Java-Fenster zu schließen und nach 5 Sekunden wieder zu öffnen. Jetzt hab ich mir ne Hauptklasse gebaut: public class Hauptfenster { JFrame mainframe = new JFrame(); MyWL mywl = new MyWL(mainframe); Hauptfenster() { //Hauptfenster: mainframe mainframe.setSize(450,340); mainframe.addWindowListener(mywl); } public static void main (String args[]) { new Hauptfenster(); } } Dazu den entsprechenden WindowListener: public class MyWL implements WindowListener { HilfsFunktionen hfs = new HilfsFunktionen(); private JFrame mainframe; public void windowClosing(WindowEvent e) { hfs.windowUnvis(mainframe); } public void windowOpened(WindowEvent e) { } public void windowClosed(WindowEvent e) { } public void windowActivated(WindowEvent e) { } public void windowDeactivated(WindowEvent e){ } public void windowIconified(WindowEvent e) { } public void windowDeiconified(WindowEvent e){ } public MyWindowListener(JFrame jframe){ this.mainframe = jframe; } } Und dann gibts eben die Klasse HilfsFunktionen... public class HilfsFunktionen { private JFrame jfrm; public void windowUnvis(JFrame mainframe) { this.jfrm = mainframe; jfrm.setVisible(false); try { Thread.sleep(5000); } catch (InterruptedException e) { System.out.println("InterruptedException e!"); } this.jfrm.setVisible(true); } } ...in der ich das Fenster mit setVisible(false) unsichtbar mache und dann nach 5 Sekunden mit setVisible(true) auf wieder sichtbar setze. Dabei ist aber folgendes Problem: - Das Fenster wird unsichtbar. - 5 Sekunden vergehen. - Das Fenster wird sichtbar -- allerdings nur für einen Bruchteil einer Sekunde und ist dann wieder unsichtbar. Weiss jmd woran das liegen könnte? Danke && Grüße starbuck
22. September 200816 j Siehe: Stichwort: Responding to Window-Closing Events. The default close operation is executed after any window listeners handle the window-closing event. So, for example, assume that you specify that the default close operation is to dispose of a frame. You also implement a window listener that tests whether the frame is the last one visible and, if so, saves some data and exits the application. Under these conditions, when the user closes a frame, the window listener will be called first. If it does not exit the application, then the default close operation — disposing of the frame — will then be performed. Gruß
22. September 200816 j Ok hat geklappt, Danke. :-) Zwar nicht direkt mit "DISPOSE_ON_CLOSE" aber mit "DO_NOTHING_ON_CLOSE". btw: ich read nicht gerne the whole ****ing manual @java.sun.com, wenn ich nicht weiss wo ich ansetzen muss ;-) Bearbeitet 22. September 200816 j von starbuck86
22. September 200816 j btw: ich read nicht gerne the whole ****ing manual @java.sun.com, wenn ich nicht weiss wo ich ansetzen muss ;-) Es gibt einen Tutorial-Überblick unter: Sun Java Tutorials. Gruß
Archiv
Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.