Example #1
0
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == clearButton) {
     history.clear();
     canvas.init();
     canvas.repaint();
   } else if (e.getSource() == redButton) {
     Command cmd = new ColorCommand(canvas, Color.red);
     history.append(cmd);
     cmd.execute();
   } else if (e.getSource() == greenButton) {
     Command cmd = new ColorCommand(canvas, Color.green);
     history.append(cmd);
     cmd.execute();
   } else if (e.getSource() == blueButton) {
     Command cmd = new ColorCommand(canvas, Color.blue);
     history.append(cmd);
     cmd.execute();
   } else if (e.getSource() == undoButton) {
     history.undo();
     canvas.repaint();
   }
 }
Example #2
0
 public void mouseDragged(MouseEvent e) {
   Command cmd = new DrawCommand(canvas, e.getPoint());
   history.append(cmd);
   cmd.execute();
 }