• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Shashi Kanta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • 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?!!
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
reposting code in readable format
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!