aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JFrame & FocusListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JFrame & FocusListener" Watch "JFrame & FocusListener" New topic
Author

JFrame & FocusListener

Pratik Khetia
Ranch Hand

Joined: Jun 29, 2001
Posts: 50
Hi I want to generate an event when there is a mouse click outside the JFrame window.
Like in my chat application, I open a JFrame for personal chat but when the user clicks outside that it is going into to the Windows taskbar which I want to prevent...so does anybody has any idea ???
thanks
Pratik
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
can't you use focusGained(FocusEvent e),focusLost(FocusEvent e) ?


All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
Pratik Khetia
Ranch Hand

Joined: Jun 29, 2001
Posts: 50
Originally posted by Alex Kravets:
can't you use focusGained(FocusEvent e),focusLost(FocusEvent e) ?

I tried using that but its not working...
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
try running this example, it should work with the focusGained(), focusLost()...
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.awt.*;
public class testEvents extends JApplet implements MouseListener, FocusListener{
Container container;
JPanel aPanel, aPanel2, aPanel3;
JButton button;
JTextField text;
public void init(){
container = getContentPane();
container.setLayout(new BorderLayout());
container.setBackground(Color.white);
aPanel = new JPanel();
//aPanel.setBackground(Color.white);
aPanel2 = new JPanel();
//aPanel2.setBackground(Color.white);
text = new JTextField(20);
button = new JButton("test");
button.addMouseListener(this);
button.addFocusListener(this);
aPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black,1),"Button Response"));
aPanel.add(text);
aPanel2.add(button);
container.add(aPanel2, BorderLayout.CENTER);
container.add(aPanel, BorderLayout.SOUTH);
}
public void mousePressed(MouseEvent e){
text.setText("You pressed a button");
}
public void mouseClicked(MouseEvent e){
text.setText("You clicked a mouse");
}
public void mouseEntered(MouseEvent e){
text.setText("You entered a mouse");
}
public void mouseExited(MouseEvent e){
text.setText(" ");
}
public void mouseReleased(MouseEvent e){
text.setText("You released a button");
}
public void focusGained(FocusEvent e){
text.setText("focus gained...");
}
public void focusLost(FocusEvent e){
text.setText("waiting for action...");
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JFrame & FocusListener
 
Similar Threads
calling application through servlet
blink the title bar
Hello Friends
how to blink the title bar - plz help urgent
idle time checking - very urgent..