

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
3 messages in org.codehaus.groovy.userRe: [groovy-user] mouselistener example| From | Sent On | Attachments |
|---|---|---|
| Dr. R. Mark Meyer | Nov 15, 2007 9:39 am | |
| Erik Husby | Nov 15, 2007 9:48 am | |
| Danno Ferrin | Nov 15, 2007 11:02 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Re: [groovy-user] mouselistener example | Actions... |
|---|---|---|
| From: | Erik Husby (mhu...@broad.mit.edu) | |
| Date: | Nov 15, 2007 9:48:06 am | |
| List: | org.codehaus.groovy.user | |
Try this
import groovy.swing.SwingBuilder import java.awt.BorderLayout import javax.swing.BorderFactory import java.awt.event.MouseListener import java.awt.event.MouseEvent import java.awt.event.MouseWheelEvent import java.awt.event.MouseMotionListener import java.awt.event.MouseWheelListener
class MouseExploration implements MouseListener, MouseMotionListener, MouseWheelListener {
def labels
def frame def swing
static void main(args) { def mouseExploration = new MouseExploration() mouseExploration.run() }
void run() { labels = [:] swing = new SwingBuilder() frame = swing.frame(title:'Title', location:[100,100], size:[1000, 150] ) { menuBar { menu(text:'File') { menuItem() { action(name:'Exit', closure:{ System.exit(0)}) } } menu(text:'Help') { menuItem() { action(name:'About', closure:{ showAbout() }) } } } panel(layout:new BorderLayout()) { tableLayout (cellpadding:1){ for ( i in ["Event", "X", "Y", "Button", "Modifiers", "ClickCount" ] ) { tr { td (align:'right', colfill:true){ label(text:"${i}: ") } td(align:'left') { labels[i] = label(); } } }
} } } frame.show()
frame.addMouseListener(this); frame.addMouseMotionListener(this); frame.addMouseWheelListener(this); }
void mouseClicked ( MouseEvent e ) { displayEvent(e) } void mouseEntered ( MouseEvent e ) { displayEvent(e) } void mouseExited ( MouseEvent e ) { displayEvent(e) } void mousePressed ( MouseEvent e ) { displayEvent(e) } void mouseReleased ( MouseEvent e ) { displayEvent(e) } void mouseDragged ( MouseEvent e ) { displayEvent(e) } void mouseMoved ( MouseEvent e ) { displayEvent(e) }
void mouseWheelMoved( MouseWheelEvent e) { labels.each { k, v -> v.text = " "}
labels['Event'].text = "${e.paramString()}" }
void showAbout() { def pane = swing.optionPane(message:'Test of Mouse event handling.') def dialog = pane.createDialog(frame, 'About MouseExploration') dialog.show() }
void displayEvent ( MouseEvent e ) { labels['Event'].text = "${e.paramString()}" labels['X'].text = "${e.x}" labels['Y'].text = "${e.y}" labels['Button'].text = "${e.button}" int i = e.modifiers labels['Modifiers'].text = "${e.getMouseModifiersText(i)}" labels['ClickCount'].text = "${e.clickCount}" } }
On Nov 15, 2007, at 12:39 PM, Dr. R. Mark Meyer wrote:
Hello all.
I'm looking for an example of using SwingBuilder and how to handle mouse movement events, mouse dragged,etc. that you find in Java's MouseMotionListener.
I searched the forums on Nabble and couldn't find anything; similar on Google.
Thanks, Mark
--
Mark Meyer Assoc. Professor Computer Science Dept. 207 WTC Canisius College 2001 Main Street Buffalo, NY 14208
http://cs.canisius.edu/~rmmeyer 716-888-2432<meyer.vcf>----------------------------------------------- ---------------------- To unsubscribe from this list please visit:
--- Erik Husby Senior Software Engineer I Broad Institute of MIT and Harvard Rm. 2139, 320 Charles St, Cambridge, MA 02141-2023 mobile: 781.354.6669, office: 617.258.9227 email: mhu...@broad.mit.edu AIM: ErikAtBroad







