Skip to main content



      Home
Home » Newcomers » Newcomers » Eclipse Event Adapter support
Eclipse Event Adapter support [message #265116] Wed, 01 October 2008 10:39 Go to next message
Eclipse UserFriend
Hello,

I have a "newbe" question to ask. There are such things as event adapters
in Java which enables us not to implement all methods for *Listeners. For
example we've got the MouseListener and MouseAdapter and so on.

The problem is that when I use adapter to deal with not needed inherited
methods Eclipse shows error at the created class. Eclipse can't see that
the adapter is "working" and there is no need to implement unused methods
form *Listener interface. When i force-run program everything works just
fine but this error icon doesn't let me sleep :D

What to do ;-)?

Sorry for my english and thank you for all help :)

Mike
Re: Eclipse Event Adapter support [message #265131 is a reply to message #265116] Wed, 01 October 2008 12:48 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

Mike wrote:
> Hello,
>
> I have a "newbe" question to ask. There are such things as event
> adapters in Java which enables us not to implement all methods for
> *Listeners. For example we've got the MouseListener and MouseAdapter and
> so on.
>
> The problem is that when I use adapter to deal with not needed inherited
> methods Eclipse shows error at the created class. Eclipse can't see that
> the adapter is "working" and there is no need to implement unused
> methods form *Listener interface. When i force-run program everything
> works just fine but this error icon doesn't let me sleep :D
>
> What to do ;-)?
>
> Sorry for my english and thank you for all help :)

I think we'll need to see some code to understand the problem, because
there is nothing in Eclipse that would prevent the adapter "pattern"
from working as you describe. In fact, many listener interfaces from the
Eclipse code itself use the same concept.

Eric
Re: Eclipse Event Adapter support [message #265143 is a reply to message #265131] Wed, 01 October 2008 13:55 Go to previous messageGo to next message
Eclipse UserFriend
Thx for response. Here is the code - i cut unrelated fragments. It does
hmm nothing - im just playing around withSwing - learning it :) Ignore
polish variables names ;-) The prgram starts and works fine. The only
problem are the errors displayed about not implemented methods of the
Mouse Listener interface:
"The type Okno1 must implement the inherited abstract method
MouseListener.mousePressed(MouseEvent)" and so on. What do i do wrong :)?


package mojeOkna;

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

public class Okno1 extends JFrame implements ActionListener,
FocusListener, MouseListener {

/**
*
*/
private static final long serialVersionUID = -7564568056401748951L;
JButton b1;
JTextArea comments;

public Okno1(String tytul) {
(...)
JPanel p=new JPanel();
MouseMonitor m=new MouseMonitor(this);

(...)
b1.addMouseListener(m);

(...)

p.add(b1);
(...)

this.setVisible(true);
}

}



class MouseMonitor extends MouseAdapter {
Okno1 o;

MouseMonitor(Okno1 arg) {
o=arg;
}

@Override
public void mouseEntered(MouseEvent e) {

Object s=e.getSource();
if(s==o.b1) System.out.println("Najechano przycisk");
}
}
Re: Eclipse Event Adapter support [message #265147 is a reply to message #265143] Wed, 01 October 2008 15:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: wegener.cboenospam.com

"Mike " <nirwan84@gmail.com> wrote in message
news:067bb4ac7c12b45726f10c9a4aaf553e$1@www.eclipse.org...
> Thx for response. Here is the code - i cut unrelated fragments. It does
> hmm nothing - im just playing around withSwing - learning it :) Ignore
> polish variables names ;-) The prgram starts and works fine. The only
> problem are the errors displayed about not implemented methods of the
> Mouse Listener interface:
> "The type Okno1 must implement the inherited abstract method
> MouseListener.mousePressed(MouseEvent)" and so on. What do i do wrong :)?
>

By adding the implements clause onto the class definition for Okno1, you are
telling the compiler that the class implements the specified interfaces. In
order for the class to actually meet this obligation, you have to code up
implementations of the methods in class Okno1. Based on your explaination
of what you are trying to accomplish, I'm guessing that you don't need the
class Okno1 to implement the interfaces. Remove the implents ... clause
from the class definition. The MouseMonitor class is the actual class that
is implementing the MouseListener interface.
>
> package mojeOkna;
>
> import java.awt.*;
> import java.awt.event.*;
> import javax.swing.*;
>
> public class Okno1 extends JFrame implements ActionListener,
> FocusListener, MouseListener {

change to
public class Okno1 extends JFrame {


>
> /**
> *
> */
> private static final long serialVersionUID = -7564568056401748951L;
> JButton b1;
> JTextArea comments;
>
> public Okno1(String tytul) {
> (...)
> JPanel p=new JPanel();
> MouseMonitor m=new MouseMonitor(this);
>
> (...)
> b1.addMouseListener(m);
>
> (...)
>
> p.add(b1);
> (...)
>
> this.setVisible(true);
> }
>
> }
>
>
>
> class MouseMonitor extends MouseAdapter {
> Okno1 o;
>
> MouseMonitor(Okno1 arg) {
> o=arg;
> }
>
> @Override
> public void mouseEntered(MouseEvent e) {
>
> Object s=e.getSource();
> if(s==o.b1) System.out.println("Najechano przycisk");
> }
> }
>
Re: Eclipse Event Adapter support [message #265174 is a reply to message #265147] Thu, 02 October 2008 15:08 Go to previous message
Eclipse UserFriend
Dave Wegener wrote:


> By adding the implements clause onto the class definition for Okno1, you are
> telling the compiler that the class implements the specified interfaces. In
> order for the class to actually meet this obligation, you have to code up
> implementations of the methods in class Okno1. Based on your explaination
> of what you are trying to accomplish, I'm guessing that you don't need the
> class Okno1 to implement the interfaces. Remove the implents ... clause
> from the class definition. The MouseMonitor class is the actual class that
> is implementing the MouseListener interface.

Works fine now - thank you very much :)
Previous Topic:docked/attached/detached/"popup" windows in eclipse java IDE doesn't stay docked
Next Topic:EJB 3.0 version choice when creating EJB project
Goto Forum:
  


Current Time: Sat Jul 19 16:00:19 EDT 2025

Powered by FUDForum. Page generated in 0.11255 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top