File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes SWT event handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "SWT event handling" Watch "SWT event handling" New topic
Author

SWT event handling

Peter Jersey
Greenhorn

Joined: Jul 24, 2009
Posts: 3
Hi all,

I have a question about good design in SWT.

Given an ApplicationWindow that has two Components, X and Y:



I want to attach a listener to button_X that reacts to mouse clicks. I want to change the label of BOTH buttons, button_X and button_Y when button_X is clicked. To change the laben of button_X in reaction to the mouse click, it is clear that I need to do something like this:

button_X.addListener(SWT.MouseDown, new SimpleListener("Display mouse down Listener"));
addListener (int eventType, Listener handler)

button_X.addMouseListener(new MouseListener() {
public void mouseDown(MouseEvent e) {
button_X.setText("Mouse Button Down");
}
}

But how can I modify properties on button_Y at the same time? I could work with static methods to get a reference to the button, but is this really the way people do this? I suppose there is a more elegant and API conforming solution.


Thanks for any hints!
Peter Jersey
Greenhorn

Joined: Jul 24, 2009
Posts: 3
Anyone? This ain't such a hard question, is it?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19675
    
  18

We don't have that many SWT users anymore, I fear...


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Peter Jersey
Greenhorn

Joined: Jul 24, 2009
Posts: 3
but why that? Have I missed the next big step after SWT/JFace?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19675
    
  18

I honestly cannot tell you. All I know is that most threads here are about Swing problems.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SWT event handling