2 Replies - 282 Views - Last Post: 12 September 2012 - 06:36 PM Rate Topic: -----

#1 learningjavabasics  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-September 12

Question about JOptionPane text box

Posted 12 September 2012 - 06:05 PM



I am doing my first program assignment for Java Early Objects that involves counting change. I have the program working(which is all we need) but I'm being a little OCD about the dialog box. Is there a way to get the text box next to "Price of Item: "? I have tried just putting the cost string in there with a comma or plus but both return an error.
Thanks for helping.

Here's my code:

 
import javax.swing.JOptionPane;
public class GideonchangeJP {

    public static void main(String[] args) {
		
		int cost;
		int change;
		int quarters;
		int dimes;
		int nickels;
		int qremainder;
		int dremainder;
		
		final int credit = 100;
		
		String inputString;
		
		inputString = JOptionPane.showInputDialog("Credit $1.00" + 
						          "\nPrice of Item: ");
		cost = Integer.parseInt(inputString); 
		
		change = credit - cost;
		quarters = change/25;
		qremainder = change%25;
		dimes = qremainder/10;
		dremainder = qremainder%10;
		nickels = dremainder/5;
		
		
		JOptionPane.showMessageDialog(null, "Your change is: " + change + " Cent(s)\n" +
							quarters + " Quarter(s)\n" +
							dimes + " Dime(s)\n" +
							nickels + " Nickel(s)");
		

		System.exit(0);
    }

}



Is This A Good Question/Topic? 0
  • +

Replies To: Question about JOptionPane text box

#2 Cuzzie  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 72
  • View blog
  • Posts: 341
  • Joined: 16-July 10

Re: Question about JOptionPane text box

Posted 12 September 2012 - 06:28 PM

I don't think the standard JOptionPane class provides any option for this. However, you can always make a new dialog class that extends from JDialog, and then position the JLabel and JTextField yourself.
Was This Post Helpful? 0
  • +
  • -

#3 learningjavabasics  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-September 12

Re: Question about JOptionPane text box

Posted 12 September 2012 - 06:36 PM

Thanks for the response, but we haven't learned any of that yet. I was just looking for a quick and easy way to do it. I guess it's good enough for now. Thanks again for replying.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1