import javax.swing.JOptionPane; import java.util.Scanner; /** * This class is just like Cats, except it prints its output on a * Canvas-like TextDisplay window that works even without BlueJ. * * @author Brad Richards * @version 1.1 */ public class CatsWithWindow { public static void main(String[] args) { TextDisplay output = new TextDisplay(); // The argument is the text that will appear in the dialog box. // Whatever the user types is returned as a String. String name = JOptionPane.showInputDialog("What's your name?"); // This prints to the TextDisplay "terminal" window: output.println("Hi "+name+", it's nice to meet you."); // We can get numeric inputs by first reading the user's input // as a String and then using a Scanner to grab an int from it. String catNumString = JOptionPane.showInputDialog("How many cats do you have?"); Scanner s = new Scanner(catNumString); int numCats = s.nextInt(); // Print the output to our TextDisplay window. output.println("Anything more than "+numCats/2+" is too many!"); } }