Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JAVA EventListerner

Status
Not open for further replies.
Feb 7, 2002
161
US
I have a little problem and was hoping that someone in the community could help. I am fairly new to JAVA and having and issue with EVENT HANDLINLG

I need to be able to listen for both KeyEvents and MouseEvents

i have this working

public class assignment extends JFrame implements KeyListener // have tried EventListener and did not work

but it will only handle key events

some insight would be grealy appreciated Thanks
Erik Butler
2000 MCSE
erikbutler@centurytel.net
 
In Java you can implement more than one interface. Therefore you could implement both KeyListener and MouseListener.
 
As wushutwist said, you can implement as many interfaces as you want, eg

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class assignment extends JFrame implements KeyListener, MouseListener
{
public static void main(String args[])
{
System.out.println("All Okay");
}

public void keyTyped(java.awt.event.KeyEvent e)
{

}
public void keyPressed(java.awt.event.KeyEvent e)
{

}
public void keyReleased(java.awt.event.KeyEvent e)
{

}
public void mouseExited(java.awt.event.MouseEvent e)
{

}
public void mouseReleased(java.awt.event.MouseEvent e)
{

}
public void mousePressed(java.awt.event.MouseEvent e)
{

}
public void mouseEntered(java.awt.event.MouseEvent e)
{

}
public void mouseClicked(java.awt.event.MouseEvent e)
{

}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top