Results 1 to 12 of 12
  1. #1
    nightrise420 is offline Member
    Join Date
    Sep 2010
    Posts
    16
    Rep Power
    0

    Default Need help getting input(first/last name) from user

    this is what i have but i need to also put in a last name and put it together in the "name" section.

    import javax.swing.JOptionPane;
    public class Assign2
    {
    public static void main(String[] args)
    {
    String name = JOptionPane.showInputDialog("Please enter your first name:");
    JOptionPane.showMessageDialog(null, "Welcome, " + name + ", to CIS 226.");
    }

    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,576
    Rep Power
    23

    Default

    Why can't you replicate what you have there for the next part of the name you need?

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by nightrise420 View Post
    this is what i have but i need to also put in a last name and put it together in the "name" section.
    What have you tried so far? You can use another JOptionPane.showInputDialog to get the other name and the two names can be simply added togther.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Oh and also before I forget, welcome to the Java-Forums!

  5. #5
    nightrise420 is offline Member
    Join Date
    Sep 2010
    Posts
    16
    Rep Power
    0

    Default

    ohhh yeahhh. but how do i add them together?

  6. #6
    nightrise420 is offline Member
    Join Date
    Sep 2010
    Posts
    16
    Rep Power
    0

    Default

    I got it! haha it's something so easy.
    But I have another question.
    when the Joptionpanel comes up, and the user hits cancel, i want a certain message to pop up. how do i do that?

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

  8. #8
    nightrise420 is offline Member
    Join Date
    Sep 2010
    Posts
    16
    Rep Power
    0

    Default

    when i press cancel, it just skips and the final output is "hello ,null, null, "message"

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by nightrise420 View Post
    when i press cancel, it just skips and the final output is "hello ,null, null, "message"
    So now you know what the JOptionPane.showInputDialog returns if the user presses "Cancel", and that is null. If you test if the returned String == null, you should be able to solve your problem.

  10. #10
    nightrise420 is offline Member
    Join Date
    Sep 2010
    Posts
    16
    Rep Power
    0

    Default

    My message dialog is showing up in a single line but i need to break it up into two lines.
    I need it like this. how can i break it up?
    Hello, Firstname + Lastname
    Welcome to CIS 226.
    JOptionPane.showMessageDialog(null, "Hello, " + firstname + " " + lastname + ", Welcome to CIS 226.");

  11. #11
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    String and its method .split().... study.

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by al_Marshy_1981 View Post
    String and its method .split().... study.
    Hm, I think the OP is asking more of a display question than a split question. Myself, I'd recommend you look into using an escape char such as "\n". i.e.,
    Java Code:
          String twoLines = "Two" + "\n" + "Lines";
          JOptionPane.showMessageDialog(null, twoLines);

Similar Threads

  1. User Input
    By brmcdani in forum New To Java
    Replies: 2
    Last Post: 02-05-2010, 01:59 AM
  2. how to get input from User
    By Alvaro in forum New To Java
    Replies: 7
    Last Post: 01-15-2010, 11:02 PM
  3. user input with JTextArea
    By andre1011 in forum Advanced Java
    Replies: 6
    Last Post: 04-16-2009, 04:09 AM
  4. User input- Pop Up Box
    By dedachi in forum AWT / Swing
    Replies: 3
    Last Post: 03-23-2009, 04:47 AM
  5. cant take input from user
    By new_1 in forum New To Java
    Replies: 6
    Last Post: 12-25-2007, 07:38 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
  •