Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Change to JOptionPane

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Change to JOptionPane

    I want to convert this java code to a joption but i am still learning java and i don't know how to do it, can anyone lend me a hand? Here's the code in buffered reader form:

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package sitwork;

    import javax.swing.*;

    public class sitwork {

    public static void main(String[] args){

    String name = JOptionPane.showInputDialog( "Desired Choice:" );
    int choice=0;
    while(choice<=7){
    System.out.println("1. Miles");
    System.out.println("2. Feet");
    System.out.println("3. Kilometer");
    System.out.println("4. Meter");
    System.out.println("5. Inches");
    System.out.println("6. Centimeter");
    System.out.println("7. Exit");

    choice=Integer.parseInt(dataln.readLine());


    switch(choice){
    case 1:
    int m;

    System.out.println("Enter Miles: ");
    m=Integer.parseInt(dataln.readLine());
    System.out.println("Feet: "+" "+ m *5279.85565107);
    System.out.println("Kilometer: "+" "+ m*1.6093);
    System.out.println("Meter: "+" "+m*1609.3);
    System.out.println("Inches: "+" "+m*63358.26781284);
    System.out.println("Centimeter: "+" "+m*160930.0002446136);

    break;
    case 2:
    int f;

    System.out.println("Enter Feet: ");
    f=Integer.parseInt(dataln.readLine());
    System.out.println("Miles: "+" "+ f *0.0001893991176);
    System.out.println("Kilometer: "+" "+ f*0.0003048);
    System.out.println("Meter: "+" "+f*0.3048);
    System.out.println("Inches: "+" "+f*12);
    System.out.println("Centimeter: "+" "+f*30.48);
    break;
    case 3:
    int k;

    System.out.println("Enter Kilometer: ");
    k=Integer.parseInt(dataln.readLine());
    System.out.println("Feet: "+" "+ k *3280.8399);
    System.out.println("Miles: "+" "+ k*0.6213882);
    System.out.println("Meter: "+" "+k*1000);
    System.out.println("Inches: "+" "+k*39370.07);
    System.out.println("Centimeter: "+" "+k*100000);
    break;
    case 4:
    int me;

    System.out.println("Enter Meter: ");
    me=Integer.parseInt(dataln.readLine());
    System.out.println("Feet: "+" "+ me *3.280839);
    System.out.println("Miles: "+" "+ me*621.3882);
    System.out.println("Kilometer: "+" "+me*1000);
    System.out.println("Inches: "+" "+me*39.3700788);
    System.out.println("Centimeter: "+" "+me*100);
    break;
    case 5:
    int i;

    System.out.println("Enter Inches: ");
    i=Integer.parseInt(dataln.readLine());
    System.out.println("Feet: "+" "+ i *3.280839);
    System.out.println("Miles: "+" "+ i*0.000015783254);
    System.out.println("Kilometer: "+" "+i*0.000025349);
    System.out.println("Meter: "+" "+i*0.02534);
    System.out.println("Centimeter: "+" "+i*2.51);
    break;
    case 6:
    int c;

    System.out.println("Enter Centemeter: ");
    c=Integer.parseInt(dataln.readLine());
    System.out.println("Feet: "+" "+ c *3.280839);
    System.out.println("Miles: "+" "+ c*0.000006218797);
    System.out.println("Kilometer: "+" "+c*0.000004);
    System.out.println("Meter: "+" "+c*0.004);
    System.out.println("Inches: "+" "+c*0.3937008);
    break;
    case 7:
    System.exit(0);
    break;
    default:
    System.out.println("INVALID INPUT! ");
    break;
    }

    }


    }

    }

    I already have changed some part of it into JOption but still doesn't work. Kindly please re-post the correct code...


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Change to JOptionPane

    but still doesn't work
    Please explain

  3. #3
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Change to JOptionPane

    On your previous thread, a moderator was kind enough to edit your post to add the code tags. how long does it take before you learn to do that yourself?

    And as Norm said, 'it doesn't work" is useless. Read more about that here (on another forum's FAQ page)
    It Doesnt Work Is Useless at JavaRanch

    db

Similar Threads

  1. Using Icons in JOptionPane
    By Jchang504 in forum AWT / Java Swing
    Replies: 3
    Last Post: September 19th, 2014, 02:28 PM
  2. JOptionPane using If and Else
    By Liuric in forum Member Introductions
    Replies: 7
    Last Post: October 1st, 2010, 12:05 AM
  3. NullPointerException when canceling JOptionPane.showInputDialog
    By Shaddam in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 2nd, 2010, 02:08 AM
  4. [SOLVED] Scroll down in JOptionPane and window problems.
    By javapenguin in forum What's Wrong With My Code?
    Replies: 60
    Last Post: June 16th, 2010, 12:04 PM
  5. JOptionPane Question/ Printing
    By 03EVOAWD in forum AWT / Java Swing
    Replies: 2
    Last Post: August 31st, 2009, 09:17 AM