protected void addBindings() {
InputMap inputMap = this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
ActionMap actionMap = this.getRootPane().getActionMap();
KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_Z, Event.CTRL_MASK);
inputMap.put(key, "undo");
actionMap.put("undo", new UndoAction());
key = KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.CTRL_MASK);
inputMap.put(key, "completed");
actionMap.put("completed", new CompletedAction());
key = KeyStroke.getKeyStroke(KeyEvent.VK_D, Event.CTRL_MASK);
inputMap.put(key, "delete");
actionMap.put("delete", new DeleteAction());
}
class UndoAction extends AbstractAction {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("*****EXECMD: UNDO*******");
JIDLogic.setCommand("UNDO");
Task[] task = JIDLogic.executeCommand("UNDO");
if(task == null)
showPopup("UNDO unsuccessfully!");
else {
showPopup("UNDO: "+task[0].getName());
expandJPanel.updateJTable();
}
}
}
class DeleteAction extends AbstractAction {
@Override
public void actionPerformed(ActionEvent e) {
Task[] taskList = expandJPanel.getTasks();
JIDLogic.setCommand("DELETE");
Task[] task = JIDLogic.executeCommand("DELETE "
+ taskList[expandJPanel.jTable1.getSelectedRow()].getTaskId());
if(task == null)
MainJFrame.showPopup("DELETE unsuccessfully!");
else {
MainJFrame.showPopup("DELETE: "+task[0].getName());
expandJPanel.updateJTable();
}
}
}
class CompletedAction extends AbstractAction {
@Override
public void actionPerformed(ActionEvent e) {
Task[] taskList = expandJPanel.getTasks();
JIDLogic.setCommand("COMPLETED");
System.out.println("COMPLETED "
+ taskList[expandJPanel.jTable1.getSelectedRow()].getTaskId());
Task[] task = JIDLogic.executeCommand("COMPLETED "
+ taskList[expandJPanel.jTable1.getSelectedRow()].getTaskId());
if(task == null)
MainJFrame.showPopup("COMPLETED unsuccessfully!");
else {
MainJFrame.showPopup("COMPLETED: "+task[0].getName());
expandJPanel.updateJTable();
}
}
This whole code is inside my class which extends JFrame.
The first and the third function can work but the second one cannot work.
There was no line printing after I pressed Ctrl+X. I have also tried chaging to other keys. But it still has problems.