View Full Version : JOptionpane input question
fobber
01-17-2007, 03:47 AM
Hi all,
I have a question regarding a JOptionpane question. I want to have a window to enter a number, and then send it to another class.
An example I would like to use is
{JOptionPane.showMessageDialog( null, "Deposit");
String input = JOptionPane.showInputDialog("Enter the deposit amount: ");
}
And as for the class,
public class Teller
{
ArrayList acct;
public void deposit(String accNum, double amt, String name)
{
}
}
I'm confused on how it can send it to another class where the methods have different parameters and not sure if it is even allowed.
brad211987
01-17-2007, 03:54 AM
To use your deposit method, you will need to get the correct types of values first. Your method takes a double value as the amount, so you will need to parse your input variable to a double like this:
double amount = Double.parseDouble(input);
You will also need to get the name and account number from the user and then pass all of that to your method through a Teller object, for example:
//create Teller object and store in variable tel
Teller tel = new Teller();
//call deposit method
tel.deposit(accountNum, amount, name);
This way, you have all of your information, and it is all sent to the deposit method to satisfy all of its required parameters.
fobber
01-17-2007, 04:12 AM
Thank you for the fast reply brad211987.
I will continue to work on this project.
thai_jedi
10-01-2008, 06:19 PM
I have this code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package bensbox;
import java.util.Scanner;
import javax.swing.JOptionPane;
/**
*
* @author Administrator
*/
public class Box {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Scanner input = new Scanner( System.in );
String side = "";
int stars; // number of stars on a side
int column; // the current column of the square being printed
int row = 1; // the current row of the square being printed
// prompt and read the length of the side from the user
side = JOptionPane.showInputDialog( null, "Enter length of side:" );
stars =Integer.parseInt(side);
if ( stars < 1 )
{
stars = 1;
JOptionPane.showMessageDialog(null, "Invalid Input\nUsing default value 1" );
} // end if
else if ( stars > 20 )
{
stars = 20;
JOptionPane.showMessageDialog(null, "Invalid Input\nUsing default value 20" );
} // end else if
// repeat for as many rows as the user entered
while ( row <= stars )
{
column = 1;
// and for as many columns as rows
while ( column <= stars )
{
if ( row == 1 )
System.out.print( "*" );
else if ( row == stars )
System.out.print( "*" );
else if ( column == 1 )
System.out.print( "*" );
else if ( column == stars )
System.out.print( "*" );
else
System.out.print( " " );
column++;
} // end inner while loop
System.out.println( );
row++;
} // end outer while loop
} // end method main
// TODO code application logic here
}
My question is how do I get the System.out.println( ); in the form of a JOptionpane.showmessage dialogue? Because I want it to pop up?
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.