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 6 of 6

Thread: Java Dialog Box HELP

  1. #1
    Junior Member Green Light's Avatar
    Join Date
    Feb 2013
    Location
    Colombo,Sri Lanka
    Posts
    3
    My Mood
    Fine
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Java Dialog Box HELP

    Hii Friends,I am new to this forum,and can anybody of you tell me how to do this.

    This is it


    First we were given to type the below given code


    import javax.swing.JOptionPane;
    public class DialogViewer1
    {
    public static void main(String[] args)
    {
    String name = JOptionPane.showInputDialog("What is your name?");
    System.out.println(name);
    System.exit(0);
    }
    }

    and that's not the problem.

    now they ask to modify the program to print “Hello, name!” displaying the name that the user typed in a Dialog Box.

    Please explain how to do that,Thanks in advance


  2. #2
    Member Zyrion's Avatar
    Join Date
    Feb 2013
    Location
    Iowa
    Posts
    106
    My Mood
    Angelic
    Thanks
    2
    Thanked 8 Times in 8 Posts

    Default Re: Java Dialog Box HELP

    Well let's break this down.

    import javax.swing.JOptionPane; //imports the package for the GUI input
    public class DialogViewer1
    {
    public static void main(String[] args)
    {
     //Create an new instance of object string
    String name = new String();
     
    //Create a GUI box to ask for the user's input and set it to string name
    name = JOptionPane.showInputDialog(null,  "What is your name?",  "Name", JOptionPane.QUESTION_MESSAGE); 
     
     //Print the word Hello on the screen and concat that string with the instance variable name.
    System.out.println("Hello! " + name);
     
    //System.exit(0); This statement ends the code abruptly and isn't necessary for this type of a java program
    }
    }

  3. The Following User Says Thank You to Zyrion For This Useful Post:

    Green Light (February 28th, 2013)

  4. #3
    Junior Member Green Light's Avatar
    Join Date
    Feb 2013
    Location
    Colombo,Sri Lanka
    Posts
    3
    My Mood
    Fine
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java Dialog Box HELP

    I am new to this Java,thx a lot bro,you saved me Rep +

  5. #4
    Member Zyrion's Avatar
    Join Date
    Feb 2013
    Location
    Iowa
    Posts
    106
    My Mood
    Angelic
    Thanks
    2
    Thanked 8 Times in 8 Posts

    Default Re: Java Dialog Box HELP

    Your welcome.

  6. #5
    Junior Member Green Light's Avatar
    Join Date
    Feb 2013
    Location
    Colombo,Sri Lanka
    Posts
    3
    My Mood
    Fine
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java Dialog Box HELP

    Quote Originally Posted by Zyrion View Post
    Your welcome.
    Hello friend,if you don't mind please answer for this question as well,I have to submit the assignment tomorrow and hardly have no time to refer the book now.Thanks in advance

    this is it.

    1 First, an input dialog box that asks: “What would you like me to do?”
    2 Then a message dialog box that says: “I'm sorry, (your name). I'm afraid I can't do that.”

  7. #6
    Member Zyrion's Avatar
    Join Date
    Feb 2013
    Location
    Iowa
    Posts
    106
    My Mood
    Angelic
    Thanks
    2
    Thanked 8 Times in 8 Posts

    Default Re: Java Dialog Box HELP

    Use the code I had given you, as a template for the program you are trying to write.

Similar Threads

  1. Help formatting Dialog box!
    By swirth123 in forum Java Theory & Questions
    Replies: 5
    Last Post: January 24th, 2013, 03:20 PM
  2. Making an input dialog box appear after closing a combo box
    By Shenaniganizer in forum What's Wrong With My Code?
    Replies: 14
    Last Post: November 11th, 2012, 06:22 PM
  3. Default Dialog box changes size
    By anu21g in forum AWT / Java Swing
    Replies: 3
    Last Post: January 2nd, 2012, 05:46 AM
  4. Java dialog box is blank in 2nd attempt while using timer.
    By mocherla81 in forum AWT / Java Swing
    Replies: 1
    Last Post: January 17th, 2011, 09:49 AM
  5. [SOLVED] Help with dialog box
    By 03EVOAWD in forum AWT / Java Swing
    Replies: 5
    Last Post: August 4th, 2009, 11:06 AM