🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #19233

Is it possible to impliment an event handler this way?

#19233
From: Art Smith
Date: Thu, 26 Feb 1998 00:00
58 lines
2260 bytes
Hi,

I'm new to java and am currently trying to develop an applet which will
contain a lot of buttons. What I want to do is have a button reverse its
foreground and background colors when the mouse enters/exits the button.
Jbuilder creates a seperate method for each button and I currently need
to add the same code to each button in order to reverse the colors. What
I want to know is if its possible to create a class that extends button
which contains an inner class which extends mouseadapter. The inner
class only impliments the mouse enter/exit code. Within the applet I
then want to be able to create instances of my "new" button which will
then reverse colors. I also need to be able to have a unique mouseclick
method for each button. The structure is currently:

public class myapp extends Applet {

mybutton first = new mybutton;

... other components ......

public void init();

first.setLabel("first");  // This works

.... additional init code......

}

public class mybutton extends Button {

  public void init()

     this.addMouseListener(MyButtonAdapter());
}

class MyButtonAdapter extends MouseAdapter {

   public void mouseEntered(MouseEvent e) {
       setBackground(Color.forgroundcolor);
       setForeground(Color.background)
  }
   public void mouseExit(MouseEvent e) {
      setBackground(Color.background);
      setForeground(Color.foreground);
  }
}

The foreground/background colors are currently hard coded,
but this will change if I can ever get it to work. Nothing happens
when the mouse enters/exits the button.

Am I missing something obvious here or is this approach just
plain wrong?

Thanks in advance,
Art Smith
arcs@stat.ufl.edu
Technical Details
Message-ID: <34F5B28C.74F5634B@stat.ufl.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,b0a7ce5755baad39,start
X-Google-Attributes: gidf74b3,public
From: Art Smith <arcs@stat.ufl.edu>
Subject: Is it possible to impliment an event handler this way?
Date: 1998/02/26
Message-ID: <34F5B28C.74F5634B@stat.ufl.edu>
X-Deja-AN: 328903138
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=us-ascii
Organization: University of Florida
Mime-Version: 1.0
Reply-To: arcs@stat.ufl.edu
Newsgroups: borland.public.jbuilder.java.language