Skip to content

Commit 3b510a8

Browse files
committed
created FancyMesageBox w/@samanthalangit
1 parent 8c64874 commit 3b510a8

5 files changed

Lines changed: 102 additions & 12 deletions

File tree

build.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0"?>
22
<project name="Teaching Kids Programming" basedir="." default="Publish TeachingKidsProgramming" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
33

4-
54
<property name="home" value="." />
65
<property name="src" value="${home}/src/main/java" />
76
<property name="rsrc" value="${home}/src/main/resources" />
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package org.teachingextensions.logo.utils.EventUtils;
2+
3+
import javax.swing.JOptionPane;
4+
5+
import org.teachingextensions.approvals.lite.util.NumberUtils;
6+
7+
/**
8+
* <img src=
9+
* "http://www.mhhe.com/engcs/compsci/wu2/graphics/wu2java/common/javabook2Doc/mbox3.gif"
10+
* style="text-align: left" alt="A message box" height="60" width="145"> <br>
11+
* <br>
12+
* <br>
13+
* <br>
14+
* <br>
15+
* Fancy MessageBox is a pop up window that you can change!<br>
16+
* Use it to collect numerical input from the user<br>
17+
* Or to display a message for the user to read.<br>
18+
*/
19+
public class FancyMessageBox
20+
{
21+
private static FancyMessageBoxInstance fancyMessageBox = new FancyMessageBoxInstance();
22+
/**
23+
* Prints a request for a numerical input to the window. <br>
24+
* <b>Example:</b>
25+
* {@code int cookies = FancyMessageBox.askForNumericalInput("How many cookies would you like?", "Cookies");}
26+
*
27+
* @param message
28+
* the text in the FancyMessageBox
29+
* @param title
30+
* the title of the FancyMessageBox
31+
* @return the user input as a number
32+
*/
33+
public static int askForNumericalInput(String message, String title)
34+
{
35+
return fancyMessageBox.askForNumericalInput(message, title);
36+
}
37+
/**
38+
* Prints a request for a text input to the window. <br>
39+
* <b>Example:</b>
40+
* {@code String name = FancyMessageBox.askForTextInput("What is your nickname?", "Nicknames");}
41+
*
42+
* @param message
43+
* the text in the FancyMessageBox
44+
* @param title
45+
* the title of the FancyMessageBox
46+
* @return the user input as a string
47+
*/
48+
public static String askForTextInput(String message, String title)
49+
{
50+
return fancyMessageBox.askForTextInput(message, title);
51+
}
52+
/**
53+
* Prints the message to the window. <br>
54+
* <b>Example:</b> {@code FancyMessageBox.showMessage("Girl programmers rule!","Just the Facts");}
55+
*
56+
* @param message
57+
* the text in the FancyMessageBox
58+
* @param title
59+
* the title of the FancyMessageBox
60+
*/
61+
public static void showMesage(String message, String title)
62+
{
63+
fancyMessageBox.showMessage(message, title);
64+
}
65+
public static void mock(FancyMessageBoxInstance messageBoxMock)
66+
{
67+
fancyMessageBox = messageBoxMock;
68+
}
69+
public static class FancyMessageBoxInstance
70+
{
71+
public int askForNumericalInput(String message, String title)
72+
{
73+
String input = askForTextInput(message, title);
74+
return NumberUtils.load(input, 0);
75+
}
76+
public String askForTextInput(String message, String title)
77+
{
78+
return JOptionPane.showInputDialog(null, message, title, -1);
79+
}
80+
public void showMessage(String message, String title)
81+
{
82+
JOptionPane.showMessageDialog(null, message, title, -1);
83+
}
84+
}
85+
}

src/main/java/org/teachingextensions/logo/utils/EventUtils/MessageBox.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public static String askForTextInput(String message)
5151
*
5252
* @param message
5353
* the text to be displayed
54+
* @param title
5455
*/
5556
public static void showMessage(String message)
5657
{

src/main/java/org/teachingkidsprogramming/recipes/completed/section06modelviewcontroller/OneFishTwoFish.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,27 @@
33
import java.util.Iterator;
44
import java.util.Scanner;
55

6+
import org.teachingextensions.logo.utils.EventUtils.FancyMessageBox;
7+
68
//*************This Lesson is In Development*****************************//
79
public class OneFishTwoFish
810
{
911
private static Scanner scanner;
1012
public static void main(String[] args)
1113
{
1214
makeAString();
13-
int fish = -10;
14-
howManyFish(fish);
15+
int numberOfFish = FancyMessageBox.askForNumericalInput("How many fishes?", "Are Fishes Like Wishes?");
16+
makeAFishyDecision(numberOfFish);
1517
}
1618
public static void makeAString()
1719
{
1820
final String input = "1 fish 2 fish red fish blue fish,black fish,blue fish,old fish,new fish ";
1921
scanner = new Scanner(input);
2022
System.err.println("\nWe have: " + input + '\n');
23+
tellAStory(input);
24+
}
25+
private static void tellAStory(final String input)
26+
{
2127
Scanner s = scanner.useDelimiter("\\s*fish\\s*");
2228
System.out.println("So: " + s.nextInt() + " and " + s.nextInt());
2329
System.out.println("And: " + s.next() + " and " + s.next() + '\n');
@@ -34,26 +40,26 @@ public Iterator<String> iterator()
3440
{
3541
System.out.println("And then: " + fish);
3642
}
37-
s.close();
43+
System.out.println("");
3844
}
39-
public static void howManyFish(int fish)
45+
public static void makeAFishyDecision(int numberOfFish)
4046
{
41-
switch (fish)
47+
switch (numberOfFish)
4248
{
4349
case -1 :
44-
System.out.println("Had a Fish");
50+
FancyMessageBox.showMesage("Had a Fish", "Not hungry anymore...");
4551
break;
4652
case 0 :
47-
System.out.println("No Fish");
53+
FancyMessageBox.showMesage("No Fish", "None");
4854
break;
4955
case 1 :
50-
System.out.println("One Fish");
56+
FancyMessageBox.showMesage("One Fish", "One");
5157
break;
5258
case 2 :
53-
System.out.println("Two Fish");
59+
FancyMessageBox.showMesage("Two Fish", "Two");
5460
break;
5561
default :
56-
System.out.println("Vegetaraian");
62+
FancyMessageBox.showMesage("Vegetaraian meal", "Fish are icky");
5763
break;
5864
}
5965
}

src/main/java/org/teachingkidsprogramming/section08events/DeepDive08Events.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.teachingextensions.logo.utils.ColorUtils.PenColors;
66
import org.teachingextensions.logo.utils.LineAndShapeUtils.Circle;
77

8-
@SuppressWarnings("unused")
98
public class DeepDive08Events
109
{
1110
// Step 1: SELECT the method name (twoTortoises on line 26), then click the Run Button

0 commit comments

Comments
 (0)