• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JFrame & FocusListener

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can't you use focusGained(FocusEvent e),focusLost(FocusEvent e) ?
 
Pratik Khetia
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 476
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...");
}
}
 
Slideshow boring ... losing consciousness ... just gonna take a quick nap on this tiny ad ...
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic