|
| 1 | +package org.teachingkidsprogramming.recipes.completed.section07events; |
| 2 | + |
| 3 | +import java.awt.Color; |
| 4 | +import java.awt.event.ActionEvent; |
| 5 | +import java.awt.event.ActionListener; |
| 6 | + |
| 7 | +import javax.swing.ImageIcon; |
| 8 | +import javax.swing.JButton; |
| 9 | + |
| 10 | +import org.teachingextensions.logo.ColorWheel; |
| 11 | +import org.teachingextensions.logo.PenColors; |
| 12 | +import org.teachingextensions.logo.Tortoise; |
| 13 | +import org.teachingextensions.logo.shapes.Circle; |
| 14 | +import org.teachingextensions.windows.MouseRightClickListener; |
| 15 | +import org.teachingextensions.windows.ProgramWindow; |
| 16 | + |
| 17 | +//***********************In Progress***************************// |
| 18 | +public class TortoiseMobile implements MouseRightClickListener |
| 19 | +{ |
| 20 | + public static void main(String[] args) |
| 21 | + { |
| 22 | + new TortoiseMobile(); |
| 23 | + } |
| 24 | + public TortoiseMobile() |
| 25 | + { |
| 26 | + Tortoise.getBackgroundWindow().addMouseRightClickListener(this); |
| 27 | + Tortoise.setSpeed(10); |
| 28 | + clearTheScreen(); |
| 29 | + prepareColorPalette(); |
| 30 | + ImageIcon arrowIconL = new ImageIcon( |
| 31 | + "../TeachingKidsProgramming.Source.Java/src/main/resources/icons/arrow-left.png"); |
| 32 | + JButton leftButton = new JButton(arrowIconL); |
| 33 | + // leftButton.setLocation(300, 100); |
| 34 | + ProgramWindow.addButton(Tortoise.getBackgroundWindow(), leftButton); |
| 35 | + ImageIcon arrowIconU = new ImageIcon( |
| 36 | + "../TeachingKidsProgramming.Source.Java/src/main/resources/icons/arrow-up.png"); |
| 37 | + JButton upButton = new JButton(arrowIconU); |
| 38 | + // rightButton.setLocation(300, 100); |
| 39 | + ProgramWindow.addButton(Tortoise.getBackgroundWindow(), upButton); |
| 40 | + ImageIcon arrowIconR = new ImageIcon( |
| 41 | + "../TeachingKidsProgramming.Source.Java/src/main/resources/icons/arrow-right.png"); |
| 42 | + JButton rightButton = new JButton(arrowIconR); |
| 43 | + // rightButton.setLocation(300, 100); |
| 44 | + ProgramWindow.addButton(Tortoise.getBackgroundWindow(), rightButton); |
| 45 | + rightButton.addActionListener(new ActionListener() |
| 46 | + { |
| 47 | + @Override |
| 48 | + public void actionPerformed(ActionEvent e) |
| 49 | + { |
| 50 | + Tortoise.turn(90); |
| 51 | + } |
| 52 | + }); |
| 53 | + leftButton.addActionListener(new ActionListener() |
| 54 | + { |
| 55 | + @Override |
| 56 | + public void actionPerformed(ActionEvent e) |
| 57 | + { |
| 58 | + Tortoise.turn(-90); |
| 59 | + } |
| 60 | + }); |
| 61 | + upButton.addActionListener(new ActionListener() |
| 62 | + { |
| 63 | + @Override |
| 64 | + public void actionPerformed(ActionEvent e) |
| 65 | + { |
| 66 | + Tortoise.move(25); |
| 67 | + } |
| 68 | + }); |
| 69 | + Tortoise.getBackgroundWindow().setVisible(false); |
| 70 | + Tortoise.getBackgroundWindow().setVisible(true); |
| 71 | + // String backGround = "/TeachingKidsProgramming.Source.Java/src/main/resources/maze.png"; |
| 72 | + // Tortoise.getBackgroundWindow().setBackgroundImage(backGround); |
| 73 | + } |
| 74 | + private static void prepareColorPalette() |
| 75 | + { |
| 76 | + ColorWheel.addColor(PenColors.Reds.Red); |
| 77 | + ColorWheel.addColor(PenColors.Greens.Green); |
| 78 | + ColorWheel.addColor(PenColors.Blues.Blue); |
| 79 | + ColorWheel.addColor(PenColors.Purples.Purple); |
| 80 | + ColorWheel.addColor(PenColors.Pinks.Pink); |
| 81 | + ColorWheel.addColor(PenColors.Greens.Teal); |
| 82 | + } |
| 83 | + private void addDot(int x, int y) |
| 84 | + { |
| 85 | + addCircle(x, y); |
| 86 | + Tortoise.moveTo(x, y); |
| 87 | + } |
| 88 | + private void addCircle(int x, int y) |
| 89 | + { |
| 90 | + int radius = 7; |
| 91 | + Color color = ColorWheel.getNextColor(); |
| 92 | + Circle circle = new Circle(radius, color); |
| 93 | + circle.setTransparency(60); |
| 94 | + circle.setCenter(x, y); |
| 95 | + circle.addTo(Tortoise.getBackgroundWindow()); |
| 96 | + } |
| 97 | + private static void clearTheScreen() |
| 98 | + { |
| 99 | + Tortoise.clear(); |
| 100 | + } |
| 101 | + @Override |
| 102 | + public void onRightMouseClick(int x, int y) |
| 103 | + { |
| 104 | + clearTheScreen(); |
| 105 | + } |
| 106 | +} |
0 commit comments