Results 1 to 2 of 2
  1. #1
    outforlunch is offline Member
    Join Date
    Sep 2012
    Posts
    4
    Rep Power
    0

    Default JOptionPane help....

    Im a 16 and teaching my self java, this is my 3rd day and i am playing with JOptionPane. i want to make all dialog pop up windows.
    Here is whats wrong.
    1.Only one comes up and then it dies.
    2.i cant get it to print my equations so it is currently a System.out.println deal going on.

    PHP Code:
    import java.util.Scanner;
    import javax.swing.JOptionPane;
    
    public class Cube {
    
    	
    	public static void main(String[] args) {
    
    	    double l;//lenght 
    		double w;//width
    		double h;//highth
    		Scanner s = new Scanner (System.in);//scanning for new star systems
    		String q = null;//user interface: volume or surface area
    		String rr;//restart string
    		int r = 0;//while loop shiz
    		
    		do{//start of the do-while
    		System.out.println("Do you want to calculate volume or surface area?");
    		q = s.nextLine();
    		if(q.equals("area")){//form for surface S = 2( l*w +l*h +w*h)
    			
    			JOptionPane.showInputDialog("What is the length?");
    			l = s.nextDouble();
    			JOptionPane.showInputDialog("What is the Width?");
    			w = s.nextDouble();
    			JOptionPane.showInputDialog("What is the highth");
    			h =  s.nextDouble();
    			
    			System.out.println("the Surface area is:" + 2*( l*w +l*h +w*h));
    			System.out.println("");
    			System.out.println("");
    			JOptionPane.showInputDialog("Restart Program? y/n");
    			rr = s.next();
    			if(rr.equals("n")){//kills the program with fire
    				System.exit(0);
    			}
    		}
    		if (q.equals("surface area")){
    			JOptionPane.showInputDialog("What is the length?");
    			l = s.nextDouble();
    			JOptionPane.showInputDialog("What is the Width?");
    			w = s.nextDouble();
    			JOptionPane.showInputDialog("What is the highth");
    			h =  s.nextDouble();
    			
    			System.out.println("the Surface area is:" + 2*( l*w +l*h +w*h));
    			System.out.println("");
    			System.out.println("");
    			JOptionPane.showInputDialog("Restart Program? y/n");
    			rr = s.next();
    			if(rr.equals("n")){
    				System.exit(0);
    			}
    		}
    			
    			
    		if(q.equals("volume")){
    		JOptionPane.showInputDialog("What is the length?");
    		l = s.nextDouble();
    		JOptionPane.showInputDialog("What is the width?");
    		w = s.nextDouble();
    		JOptionPane.showInputDialog("What is the highth?");
    		h = s.nextDouble();
    	    JOptionPane.showMessageDialog(null, "They area of your cube is "+ l * w * h);
    		System.out.println("");
    		System.out.println("");
    		JOptionPane.showConfirmDialog(null, "Restart? y/n");
    		rr = s.next();
    		if(rr.equals("n")){
    					System.exit(0);
    		}
    		
    		System.out.println("");
    		
    		}
    		}
    		
    	
    		while(r < 1);
    		
    		
    		}
    	}

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,791
    Rep Power
    25

    Default Re: JOptionPane help....

    You shouldn't mix console I/O (the Scanner class) with GUI I/O (JOptionPane)
    Use System.out.println() to show messages on the console when reading input from the console. Get rid of JOptionPane
    Or read the String returned by the showInputDialog() method and get rid of the Scanner class.

    then it dies.
    Please copy the full text of the error messages and paste them here.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. JOptionPane
    By thorobred in forum Eclipse
    Replies: 4
    Last Post: 04-19-2011, 05:15 AM
  2. need help with a JOptionPane
    By dr4g0nk1ng in forum Advanced Java
    Replies: 2
    Last Post: 02-19-2010, 10:40 PM
  3. need help for JOptionPane....
    By keycoffee in forum New To Java
    Replies: 1
    Last Post: 02-09-2010, 09:59 AM
  4. JOptionpane
    By tommyyyy in forum New To Java
    Replies: 2
    Last Post: 03-20-2009, 09:33 AM
  5. JOptionPane
    By Mir in forum New To Java
    Replies: 5
    Last Post: 11-29-2008, 03:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •