• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to write focus listener or window listener for a Window sub class?!!

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi guys,
How to write focus listener or window listener for a Window sub class?!!
i have tried with the focusGained() method of the FocusListener interface and with the windowActivated() method of the WindowListener interface. but..none of these methods receive the events!! how's that?!!
is it a bug with Java?!!
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure what you mean. I could guess, but let's not walk that route, yet. Could you post an example (in the simplest form possible) of what you are attempting?
 
Shashi Kanta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the sample code is as follows
import java.awt.*;
import java.awt.event.*;

class subWindow extends Window{
subWindow(Frame owner){
super(owner);

Button b1=new Button("Press me");
setSize(200,200);
setLayout(new FlowLayout());
setVisible(true);
addFocusListener(new myFocusAdapter(this));
addWindowListener(new myWindowAdapter(this));
addComponentListener(new myComponentAdapter(this));

}
}

class subFrame extends Frame{
subWindow win;
subFrame(){
super();
win=new subWindow(this);
}
}

class myFocusAdapter extends FocusAdapter{
subWindow win;
public myFocusAdapter(subWindow win){
this.win=win;
}
public void focusGained(FocusEvent we){ // this doesn't get invoked
System.out.println("Focus Gained");
}
}
class myWindowAdapter extends WindowAdapter{
subWindow win;
public myWindowAdapter(subWindow win){
this.win=win;
}
public void windowClosing(WindowEvent we){ // this gets invoked
win.dispose();
System.exit(0);
}
public void windowActivated(WindowEvent we){ // this doesn't get invoked
System.out.println("Window activated");
}
}
class myComponentAdapter extends ComponentAdapter{
subWindow win;
public myComponentAdapter(subWindow win){
this.win=win;
}
public void componentMoved(ComponentEvent ce){ // this gets invoked
System.out.println("Component moved");
}
public void componentShown(ComponentEvent ce){ // this doesn't get invoked
System.out.println("Component shown");
}
}
public class transApp{
public static void main(String args[]){
new subFrame();
}
// hope u can find out the bug in my program
rgds
Shashi
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's make this even easier on those that might try to help you and/or follow the conversation to learn something. You can format the display of your code using the [ code ] and [ /code ] UBB Tags (without the spaces). Thanks
 
Shashi Kanta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
reposting code in readable format
 
Yeast devil! Back to the oven that baked you! And take this tiny ad too:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic