3 messages in org.codehaus.groovy.userRe: [groovy-user] mouselistener example
FromSent OnAttachments
Dr. R. Mark MeyerNov 15, 2007 9:39 am 
Erik HusbyNov 15, 2007 9:48 am 
Danno FerrinNov 15, 2007 11:02 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [groovy-user] mouselistener exampleActions
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:

http://xircles.codehaus.org/manage_email