Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void handle(Event event) {
- if (event.getSource() instanceof Tile) {
- Tile tile = (Tile) event.getSource();
- if (event.getEventType().equals(MouseEvent.MOUSE_CLICKED)) {
- if (((MouseEvent) event).getButton().equals(MouseButton.SECONDARY))
- tile.toggleFlag();
- else if (((MouseEvent) event).getClickCount() == 2)
- mineField.massClick(tile);
- }
- if (event.getEventType().equals(MouseEvent.DRAG_DETECTED))
- if (!((MouseEvent) event).getButton().equals(MouseButton.SECONDARY))
- tile.startFullDrag();
- if (event.getEventType().equals(MouseDragEvent.MOUSE_DRAG_ENTERED))
- tile.arm();
- if (event.getEventType().equals(MouseDragEvent.MOUSE_DRAG_EXITED))
- tile.disarm();
- if (event.getEventType().equals(MouseDragEvent.MOUSE_DRAG_RELEASED))
- mineField.clickedTile(tile);
- if (event.getEventType().equals(ActionEvent.ANY))
- mineField.clickedTile(tile);
- }
- }
- public class Main extends Application {
- @Override
- public void start(Stage primaryStage) {
- try {
- StackPane root = new StackPane();
- root.addEventFilter(MouseEvent.MOUSE_PRESSED, e -> {
- if( e.isPrimaryButtonDown() && e.isSecondaryButtonDown()) {
- System.out.println( "Both down");
- } else if( e.isPrimaryButtonDown()) {
- System.out.println( "Primary down");
- } else if( e.isSecondaryButtonDown()) {
- System.out.println( "Secondary down");
- }
- });
- Scene scene = new Scene(root,400,400);
- primaryStage.setScene(scene);
- primaryStage.show();
- } catch(Exception e) {
- e.printStackTrace();
- }
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
- public class Main extends Application {
- BooleanProperty primaryMouseButtonDown = new SimpleBooleanProperty();
- BooleanProperty secondaryMouseButtonDown = new SimpleBooleanProperty();
- @Override
- public void start(Stage primaryStage) {
- try {
- StackPane root = new StackPane();
- root.addEventFilter(MouseEvent.MOUSE_PRESSED, e -> {
- primaryMouseButtonDown.setValue( e.isPrimaryButtonDown());
- secondaryMouseButtonDown.setValue( e.isSecondaryButtonDown());
- });
- root.addEventFilter(MouseEvent.MOUSE_RELEASED, e -> {
- primaryMouseButtonDown.setValue( e.isPrimaryButtonDown());
- secondaryMouseButtonDown.setValue( e.isSecondaryButtonDown());
- });
- BooleanBinding binding = Bindings.and(primaryMouseButtonDown, secondaryMouseButtonDown);
- binding.addListener( new ChangeListener<Boolean>() {
- @Override
- public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
- System.out.println( "Mouse Button Event: " + oldValue + " -> " + newValue);
- }
- });
- Scene scene = new Scene(root,400,400);
- primaryStage.setScene(scene);
- primaryStage.show();
- } catch(Exception e) {
- e.printStackTrace();
- }
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
- boolean mouse_1, mouse_2 = false;
- public void mousePressed(MouseEvent e){
- //The numbers are just made up I don't remember the actual codes for the buttons but it's simple enough to figure out.
- if(e.getButton()==1){
- mouse_1 = true;
- }
- if(e.getButton()==2){
- mouse_2 = true;
- }
- if(mouse_1&&mouse_2){
- //Your code here
- }
- }
- public void mouseReleased(MouseEvent e){
- if(e.getButton() == 1){
- mouse_1 = false;
- }
- if(e.getButton() == 2){
- mouse_2 = false;
- }
- }
- //flag to track both buttons being pressed
- private boolean wereBothButtonsPressed = false;
- private void onMousePressed(MouseEvent e) {
- //single button press sets flag to false
- wereBothButtonsPressed = e.isPrimaryButtonDown() && e.isSecondaryButtonDown();
- }
- private void onMouseReleased(MouseEvent e) {
- if (e.isPrimaryButtonDown() || e.isSecondaryButtonDown()) {
- //do nothing if user is still holding the button
- return;
- }
- if (wereBothButtonsPressed) {
- System.out.prinln("Both buttons");
- } else if (e.getButton() == MouseButton.PRIMARY) {
- System.out.prinln("Only primary");
- } else if (e.getButton() == MouseButton.SECONDARY) {
- System.out.prinln("Only secondary");
- }
- }
- private boolean wereBothButtonsPressed = false;
- @Override
- public void handle(Event event) {
- ...
- if (event.getEventType().equals(MouseEvent.MOUSE_PRESSED)) {
- MouseEvent me = (MouseEvent) event;
- wereBothButtonsPressed = me.isPrimaryButtonDown() && me.isSecondaryButtonDown();
- } else if (event.getEventType().equals(MouseEvent.MOUSE_RELEASED)) {
- MouseEvent me = (MouseEvent) event;
- if (!me.isPrimaryButtonDown() && !me.isSecondaryButtonDown()) {
- if(wereBothButtonsPressed) {
- mineField.massClick(tile);
- } else if(me.getButton() == MouseButton.PRIMARY) {
- mineField.clickedTile(tile);
- } else if(me.getButton() == MouseButton.SECONDARY) {
- tile.toggleFlag();
- }
- }
- ...
Add Comment
Please, Sign In to add comment