@Override public void mouseClicked(MouseEvent arg0) { // LEFT BUTTON // toggle between normal and reverse drive mode if (arg0.getButton() == MouseEvent.BUTTON1 && arg0.getClickCount() == 2) { // reverse drive direction selected isNormalDrive = !isNormalDrive; // apply reverse compass map if reverse drive is selected if (isNormalDrive) lbBkg.setIcon(new ImageIcon("images/kAPPframe.png")); else lbBkg.setIcon(new ImageIcon("images/kAPPframeRev.png")); // recalculate KAPP icon position within the toggled compass map xLab += (int) (arg0.getX() - wLab / 2); /* current */ yLab += (int) (arg0.getY() - hLab / 2); int xCmd = -(xLab - xRef); int yCmd = -(yRef - yLab); xLab = xCmd + xRef; /* new */ yLab = yRef - yCmd; // redraw kAPP icon lbKAPP.setBounds(xLab, yLab, wLab, hLab); lbKAPP.repaint(xLab, yLab, wLab, hLab); // drag the mouse pointer on top of the KAPP icon xFrm = frame.getX(); yFrm = frame.getY(); int newMouseX = xLab + xBrd + (int) (wLab / 2) + xFrm; int newMouseY = yLab + 4 * yBrd + (int) (hLab / 2) + yFrm; try { Robot robot = new Robot(); robot.mouseMove(newMouseX, newMouseY); } catch (AWTException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } // WHEEL BUTTON // increase/decrease wheel speed (in calibration only) if (arg0.getButton() == MouseEvent.BUTTON2 && cmdCalibrate) { DE.encodeSpecialCommands(DataExchange.SPDLEV_CMD); DE.incSpeedLevel(); lbKAPP.setToolTipText("SPEED LEVEL: " + DE.getSpeedLevel()); } // RIGHT BUTTON // send START/STOP special commands if (arg0.getButton() == MouseEvent.BUTTON3) { if (arg0.getClickCount() >= 2) { // toggle STOP/START command: // true => STOP_CMD; false => START_CMD cmdStartStop = !cmdStartStop; if (cmdStartStop) { DE.encodeSpecialCommands(DataExchange.STOP_CMD); lbKAPP.setToolTipText("*STOP*"); frame.setIconImage(Toolkit.getDefaultToolkit().getImage("images/kAPPstop.png")); } else { DE.encodeSpecialCommands(DataExchange.START_CMD); cmdCalibrate = false; lbKAPP.setToolTipText("*GO*"); frame.setIconImage(Toolkit.getDefaultToolkit().getImage("images/kAPPgo.png")); } } // send CALIBRATE special command if (cmdStartStop && (arg0.getClickCount() == 1)) { // if the Stop command is issued, perform command Motors calibration cmdCalibrate = true; DE.encodeSpecialCommands(DataExchange.CAL_CMD); lbKAPP.setToolTipText("*CALIBRATION*"); frame.setIconImage(Toolkit.getDefaultToolkit().getImage("images/kAPPcal.png")); } } }