Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #3777 > unrolled thread
| Started by | "Volker Raum" <volker.raum@THRWHITE.remove-dii-this> |
|---|---|
| First post | 2011-04-27 15:46 +0000 |
| Last post | 2011-04-27 15:47 +0000 |
| Articles | 6 — 3 participants |
Back to article view | Back to comp.lang.java.gui
Listener for opening Wind "Volker Raum" <volker.raum@THRWHITE.remove-dii-this> - 2011-04-27 15:46 +0000
Re: Listener for opening "Piet Blok" <piet.blok@THRWHITE.remove-dii-this> - 2011-04-27 15:46 +0000
Re: Listener for opening "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:46 +0000
Re: Listener for opening "Piet Blok" <piet.blok@THRWHITE.remove-dii-this> - 2011-04-27 15:46 +0000
Re: Listener for opening "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:46 +0000
Re: Listener for opening "Volker Raum" <volker.raum@THRWHITE.remove-dii-this> - 2011-04-27 15:47 +0000
| From | "Volker Raum" <volker.raum@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:46 +0000 |
| Subject | Listener for opening Wind |
| Message-ID | <g5k5mq$o58$1@murphy.mediascape.de> |
To: comp.lang.java.gui Hi all, i am looking for a way to register a listener to be informed whenever a window (Dialog) is opened in my application. I do not want to keep track in may placec for that. I am interested in a central place. I hope you can help me. Greetings Volker --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [next] | [standalone]
| From | "Piet Blok" <piet.blok@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:46 +0000 |
| Subject | Re: Listener for opening |
| Message-ID | <487dc5f0$0$88882$dbd4f001@news.wanadoo.nl> |
| In reply to | #3777 |
To: comp.lang.java.gui
Volker Raum <Volker.Raum@heitec.de> wrote in
news:g5k5mq$o58$1@murphy.mediascape.de:
> Hi all,
> i am looking for a way to register a listener to be informed whenever
> a window (Dialog) is opened in my application.
> I do not want to keep track in may placec for that.
> I am interested in a central place.
>
> I hope you can help me.
>
> Greetings
> Volker
>
Hi Volker,
You need to add an AWTEventListener to the default Toolkit.
Please see an example below.
Hope this helps.
Piet
import java.awt.AWTEvent;
import java.awt.Toolkit;
import java.awt.event.AWTEventListener;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class WindowMonitor {
public static void main(String[] args) {
registerGeneralWindowListener();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (int index = 0; index < 3; index++) {
createWindow(index);
}
}
private void createWindow(int number) {
JFrame frame = new JFrame(String.valueOf(number));
frame.setName(String.valueOf(number));
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(200, 200);
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
});
}
private static void registerGeneralWindowListener() {
AWTEventListener listener = new AWTEventListener() {
@Override
public void eventDispatched(AWTEvent event) {
if (event instanceof WindowEvent) {
WindowEvent windowEvent = (WindowEvent) event;
System.out.println(windowEvent.getWindow().getName()
+ " event type "
+ getDescription(windowEvent.getID()));
}
}
private String getDescription(int eventID) {
switch (eventID) {
case WindowEvent.WINDOW_ACTIVATED:
return "activated";
case WindowEvent.WINDOW_CLOSED:
return "closed";
case WindowEvent.WINDOW_CLOSING:
return "closing";
case WindowEvent.WINDOW_DEACTIVATED:
return "deactivated";
case WindowEvent.WINDOW_DEICONIFIED:
return "deiconified";
case WindowEvent.WINDOW_GAINED_FOCUS:
return "gained focus";
case WindowEvent.WINDOW_ICONIFIED:
return "iconified";
case WindowEvent.WINDOW_LOST_FOCUS:
return "lost focus";
case WindowEvent.WINDOW_OPENED:
return "opened";
default:
return "undefined";
}
}
};
Toolkit.getDefaultToolkit().addAWTEventListener(listener,
AWTEvent.WINDOW_EVENT_MASK);
}
}
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:46 +0000 |
| Subject | Re: Listener for opening |
| Message-ID | <7713de68-555b-4ae4-a091-687516d255f4@y38g2000hsy.googlegroups.com> |
| In reply to | #3778 |
To: comp.lang.java.gui On Jul 16, 7:57=A0pm, Piet Blok <p@b> wrote: > Volker Raum <Volker.R...@heitec.de> wrote innews:g5k5mq$o58$1@murphy.medi= ascape.de: > > > Hi all, > > i am looking for a way to register a listener to be informed whenever > > a window (Dialog) is opened in my application. =2E.. > You need to add an AWTEventListener to the default Toolkit. > > Please see an example below. That example works for the first* time a Window (/Dialog etc.) is opened, but not if it is opened a number of times. * WindowListener.windowOpened() -> "Invoked the first time a window is made visible. " The OP might look into a ComponentListener and specifically the componentShown() method as an altenative for Windows(/Dialogs) that appear multiple times. OTOH - > > I do not want to keep track in may placec for that. > > I am interested in a central place. This entire design smells fishy to me. -- Andrew Thompson http://pscode.org/ --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Piet Blok" <piet.blok@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:46 +0000 |
| Subject | Re: Listener for opening |
| Message-ID | <487e1931$0$60205$dbd49001@news.wanadoo.nl> |
| In reply to | #3779 |
To: comp.lang.java.gui Andrew Thompson <andrewthommo@gmail.com> wrote in news:7713de68-555b-4ae4-a091-687516d255f4@y38g2000hsy.googlegroups.com: > On Jul 16, 7:57apm, Piet Blok <p@b> wrote: >> Volker Raum <Volker.R...@heitec.de> wrote >> innews:g5k5mq$o58$1@murphy.medi > ascape.de: > > That example works for the first* time a Window > (/Dialog etc.) is opened, but not if it is opened > a number of times. > > OTOH - > > This entire design smells fishy to me. > > -- > Andrew Thompson > http://pscode.org/ > Andrew, Please leave it to Volker to decide what he wants to achieve. He states that he wants to be informed in a central place about windows opening. Then, what is "opening". He may eventually decide that rather he wants to monitor window activated or whatever. Why do you think his design smells fishy when you have no clue what he is after to accomplish? Piet --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:46 +0000 |
| Subject | Re: Listener for opening |
| Message-ID | <115171a7-1fba-44bd-962c-fc9b4e30f78c@c65g2000hsa.googlegroups.com> |
| In reply to | #3781 |
To: comp.lang.java.gui On Jul 17, 1:52=A0am, Piet Blok <p@b> wrote: =2E.. > Please leave it to Volker to decide what he wants to achieve. What?! Don't be silly. My suggestions/points were no more 'commanding' than yours. > He states that he wants to be informed in a central place about windows > opening. 'What an OP wants' is often secondary to good design. -- Andrew Thompson http://pscode.org/ --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Volker Raum" <volker.raum@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:47 +0000 |
| Subject | Re: Listener for opening |
| Message-ID | <g64rka$m97$1@murphy.mediascape.de> |
| In reply to | #3783 |
To: comp.lang.java.gui Keep Cool Guys, I also stumbled about the AWT Event Listener in Runtime. I already used it and it works for me. It has nothing to do with the architecture/design of a software. It is only used for testing software. I hope this pleases you. Thanx for your help. Cheers Volker Andrew Thompson schrieb: > On Jul 17, 1:52 am, Piet Blok <p@b> wrote: > ... >> Please leave it to Volker to decide what he wants to achieve. > > What?! Don't be silly. My suggestions/points were > no more 'commanding' than yours. > >> He states that he wants to be informed in a central place about windows >> opening. > > 'What an OP wants' is often secondary to good design. > > -- > Andrew Thompson > http://pscode.org/ --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.gui
csiph-web