Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Fenster schließen und nach 5 Sekunden wieder öffnen

Empfohlene Antworten

Veröffentlicht

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

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ß

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 von starbuck86

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.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.