Skip to main content

MouseAdapter not recognized

3 replies [Last post]
tskale
Offline
Joined: 2005-08-17
Points: 0

Hi:

I need to detect double click on a table. Code fragment to capture mouse event is given below:

import java.awt.event.*;

Table {
var tableListener: MyTableListener = new MyTableListener()
gridColor: Color
row:Row

......
mouseListener: tableListener

}

public class MyTableListener extends MouseAdapter
{
operation mouseClicked( e: MouseEvent);
}

operation MyTableListener.mouseClicked( e: MouseEvent)
{
System.out.println("mouse clicked");
}

The compiler gives following error:
incompatible types: expected java.awt.event.MouseListener, found MyTableListener in mouseListener: tableListener

What seems to be the problem? MyTableListener is a MouseListener as it extends MouseAdapter.
Any help will be appreciated.

~Tushar

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tskale
Offline
Joined: 2005-08-17
Points: 0
tskale
Offline
Joined: 2005-08-17
Points: 0

Thanks. That works. I had to use operation instead of function.

On mouse click I need to get data in the selected row.
Could you plese show the code fragment to do that?
Thanks a lot.

~ Tushar

alexsch
Offline
Joined: 2007-07-12
Points: 0

Try to use [b]onMouseClicked[/b] attribute. For example:

[code]
import javafx.ui.*;
import java.lang.System;

var N = 4;

Frame {
title: "JavaFX Table"
width: 300
height: 150

content: Table {
columns: [
TableColumn { text: "number" },
TableColumn { text: "square" },
TableColumn { text: "cube" }
]

cells: for( n in [1..N]) [
TableCell{ text: "{n}" },
TableCell{ text: "{n*n}" },
TableCell{ text: "{n*n*n}" }
]

onMouseClicked: function(e: MouseEvent){
if(e.clickCount == 2){
System.out.println("Double click!");
}
}
}

visible: true
}
[/code]

The code is written on compiler version of JavaFX Script language.
See http://java.sun.com/developer/technicalArticles/scripting/javafx/ria_1/