I am trying to implement an Event on a RadioButton:
radio_Email.addSelectionListener(
new org.eclipse.swt.events.SelectionListener() {
public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
// TODO Auto-generated Event stub widgetDefaultSelected()
}
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
System.out.println("This is printed twice "
+ "if i try to toggle between two radio buttons");
}
}
);
I know this is getting called twice : the first time for deselecting the first radio button and the second time for selecting the second radio button.
But i could not figure out how to solve it....can anybody help me with this
Note: The radio buttons are generated dynamically so there might be n radio buttons and hence this is inside a for-loop(just in-case..some additional info)...on page load..when i select the first one, event is called once...but when I click on a second one...then the event is getting fire twice.
Thanks in advance
i have solved it....
modify the widgetselected method as
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
boolean isSelected = ((Button)e.getSource()).getSelection();
if(isSelected){
system.out.println("Now this solved the problem")
}
}
Related
I need to get an event fired after clicking on a grid cell. It works but fires multiple events.
My Code:
private void gridClickHandler(final boolean cardDeterminer) {
gridClickHandler = new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
int cellIndex = view.getGrid().getCellForEvent(event)
.getCellIndex(); // get clicked cell of grid
if (cardDeterminer)
oasisCardRPC(cellIndex); //rpc based on clicked cell
else
desertCardRPC(cellIndex); //rpc based on clicked cell
}
};
view.getGrid().addClickHandler(gridClickHandler);
}
The method gridClickHandler is called in an onSuccess of a RPC and calls a new RPC using a boolean passed. (it works like this: click on some widget, when success then click on grid. Grid should only fire event, when this some widget was clicked directly before)
I don't know how to create a new ClickHandler only once for the grid and still make its clickHandler only fire events, when needed.
Thanks in advance!
Use a boolean : isClickHandlerAttached
Initially false, first time you add the clickhandler put it on true. Only attach if boolean is false.
I am making a game with ui controller. i use button to make that controller.
in the picture, i have "A" button. when my "character" facing npc, i want to talk with that npc with click that button. when dialogue is over, i need to close the dialogue box using this button too.
but what i got is, this button clicked over and over, so the first dialogue is skipped, and the dialogue which is showed up is the third or maybe the fourth dialog.
i attach event trigger on this button.
and this is my code that is attached on that event trigger
using UnityEngine;
using System.Collections;
public class aButtonScript : MonoBehaviour {
void Start(){
}
public void click(){
if(walkingScript.walking.interact == true)
{
loadGame.loadSave.objPrince.GetComponent<plantingScript>().aButton = false;
loadGame.loadSave.objPrince.GetComponent<walkingScript>().aButton = true;
}
}
public void clicked()
{
if(plantingScript.planting.toolBoxCanvas != null)
{
loadGame.loadSave.objPrince.GetComponent<plantingScript>().aButton = false;
choosingTools.ct.setTool();
}
}
public void unclicked()
{
loadGame.loadSave.objPrince.GetComponent<plantingScript>().aButton = false;
}
}
well, this is my first time making a game. hope whoever who read this question can help me. sorry for my bad english. thank you.
Not quite sure, but I've had similar problems when using GetMouseButton instead of GetMouseButtonDown. The first one triggers for each frame the button is pressed. Looking at your UI setup it seems you acivate the script when the button is pressed, for each frame it is pressed, and finally when it is released.
So i have this JavaFX application, which contains a button, that is supposed to open the DirectoryChooser onclick. When i trigger it once, it does what it was supposed to do, perfectly fine. As soon as i close the DirectoryChooser Dialog, the button doesn't do anything anymore. I was searching the web for some "event resetting" or something similar, because i thought maybe the Event was still "active" and therefore doesn't trigger anymore, but without any results:
// first attempt
button.addEventFilter(MouseEvent.MOUSE_CLICKED,
new EventHandler<MouseEvent>() {
public void handle(MouseEvent e) {
// dirChooser.setTitle("Select Directory:");
file = dirChooser.showDialog(primaryStage);
// just incase only the DirectoryChooser wasn't opening
System.out.println("asdf");
// updates the application view with the new selected path
update();
// not sure, if this affects anything
// found it while looking for resetting of events
e.consume();
};
}
);
// secont attempt
button.setOnAction(new EventHandler<ActionEvent>() {
#Override public void handle(ActionEvent e) {
DirectoryChooser dirChooser = new DirectoryChooser();
dirChooser.setTitle("Select Directory:");
file = dirChooser.showDialog(primaryStage);
update();
}
});
Not sure if this is just a complete wrong approach, or if i'm missing something important there. I hope you guys can figure it out.
So after the help of Uluk Biy, i got the problem. In the update routine, the button is newly created and therefore it's event handler is not existent anymore. I added the button to the attributes so I don't need to replace it everytime when calling the update routine, and the event handler is still existent.
I have a CellTable with ClickableCell. When I click on it, a popup opens and show the clicked cell table as exepected. The CellTable is added in a AbsolutePanel(Parent).
For some developpment, an another AbsolutePanel(Over) is located over the CellTable.
How can I propagate the AbsolutePanel(Over) click event on the celltable ?
I had an handler on the AbsolutePanelHandler(Over) and fired the clicked event :
absolutePanelOver.addDomHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
NativeEvent nativeEvent = Document.get().createClickEvent(0, -event.getScreenX(), event.getScreenY(),
event.getClientX(), event.getClientY(), event.isControlKeyDown(), event.isAltKeyDown(),
event.isShiftKeyDown(), event.isMetaKeyDown());
DomEvent.fireNativeEvent(nativeEvent, cellTable);
}
}, ClickEvent.getType());
Unfortunately the popup cell table is not shown. But I know that the cellTable handles the event.
Regards
Maybe I did not understand your question, but the solution seems to be much simpler.
absolutePanelOver.addDomHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
doSomething();
}
}, ClickEvent.getType());
In your CellTable you invoke the same doSomething() method when a cell is clicked. Now it does not matter whether a cell or an absolute panel is clicked - the same method will be executed.
When using a bindingNavigator and bindingSource and clicking a move button or add button or delete button, the bindingSource completes its action code before the click handler of the button (i.e. user code)
This prevents a save action on the row change. I'd like to find a bindingSource hook, something like 'beforeRowChange'.
I can subclass the bindingSource and get ahead of the add or remove event but that doesn't cover all the row move actions.
Any clues, suggestions welcome.
The BindingNavigator has a property called 'DeleteItem'.
Change this property from 'BindingNavigatorDeleteItem' to '(none)'.
private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
{
if ( bindingSource.Count > 0 )
{
if (MessageBox.Show("Confirm Delete?", "Warning", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
{
bindingSource.RemoveCurrent();
}
}
}