> Hi, can someone please tell me how to write a method
> that returns a String using JOptionPane?
>
> Thanks
Here is one simple example:
String creditcard = JOptionPane.showInputDialog("Please enter you credit card number:");
For more examples, check the JOptionPane API and tutorial:
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JOptionPane.html
http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html
hmmm, I seem to be confused on this.
The assignment I have is as follows:
For this homework you are to produce the following methods that can be used to hide the JOptionPane code :
NamePurpose
getIntReturns an integer value
getDoubleReturns a double value
getStringReturns a string
outputMessage Outputs a messge via a JoptionPane
> hmmm, I seem to be confused on this.
>
> The assignment I have is as follows:
>
> For this homework you are to produce the following
> methods that can be used to hide the JOptionPane
> code :
>
> NamePurpose
> getIntReturns an integer value
> getDoubleReturns a double value
> getStringReturns a string
> outputMessage Outputs a messge via a JoptionPane
Well, as for the getString() method, you should be able to use the code I posted. Just put it inside a method that you call getString. The method should probably take one input argument, which is the message the user will see ("Please enter you credit card number:" in my example). And instead of storing the return value from the JOptionPane in a variable, you just return it from the getString method.
About the other methods you need to write, a good place to start would be the links I posted. It's your homework, after all, not mine :-)