I have two actors which when clicked create an input box, one allows the user to enter a height (actor name= height) and one allows the user to enter a width (actor name= reply).
Once these have been entered I wanted to use the user's answers and multiply them, then display this answer on the screen. The issue I am having is that I am not sure how to create variables for these answers and how to then multiply them (as they are recognised as strings) finally displaying this answer on the screen.
Please help;
The code I have for the actor 'Reply':
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import javax.swing.JOptionPane;
import java.awt. Color;
/**
* Displays a string for the answer and when clicked will display an input box.
*
* @author
* @version 1.0
*/
public class Reply extends Actor
{
private String inputStr;
private int buttonNbr;
private Label phoneMsg;
/**
* Creates the text.
*/
public Reply()
{
setImage(new GreenfootImage("*click here to enter the width*", 20, Color.red, Color.white));
}
/**
* Creates an input box, when the text is clicked
*/
public void act()
{
if (Greenfoot.mousePressed(this)) {
makeDialog();
}
}
/**
* The code for the input box
*/
public void makeDialog()
{
inputStr = JOptionPane.showInputDialog(
"Please enter the width in cm");
buttonNbr = JOptionPane.showConfirmDialog(
null, "Are you sure?");
String msg = "The width is: " + inputStr + "cm";
JOptionPane.showMessageDialog(null, msg);
}
}

