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

Thread: Java Help for a begginer

  1. #1
    Member
    Join Date
    Jan 2013
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java Help for a begginer

    im new to java but am getting better at it. My question today is for my two display lines how do i make them display on the same window instead of displaying sepretly?

    import javax.swing.JOptionPane;
     
    public class gui{
     
    public static void main(String[] args) {
     
     
    	String name=
    		JOptionPane.showInputDialog("What is your name?");
     
    	String names=
    		JOptionPane.showInputDialog("What is your favorite color?");
     
     
     
     
    		String mes =
    			String.format("Your name is %s", name);
     
     
    		String mess =
    			String.format("Your favorite color is %s", names);
     
     
     
    		JOptionPane.showMessageDialog(null, mess);
    		JOptionPane.showMessageDialog(null, mes);
    }
     
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,210
    Thanks
    52
    Thanked 2,294 Times in 2,265 Posts

    Default Re: Java Help for a begginer

    display on the same window
    Build one String with all the lines to be displayed separated by newline characters: (\n) and display that.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Jan 2013
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Help for a begginer

    Thank you so much. now how do i get it to obtain the name and color in one window? if i do it like the output then it will use both of them for %s and i want two different answers.
    Current code:
    import javax.swing.JOptionPane;
     
    public class gui{
     
    public static void main(String[] args) {
     
     
    	String name=
    		JOptionPane.showInputDialog("What is your name?");
     
    	String names=
    		JOptionPane.showInputDialog("What is your favorite color?");
     
    		String mess =
    			String.format("Your name is %s \nYour Favorite color is %s", name, names);
     
     
    		JOptionPane.showMessageDialog(null, mess);
     
    	}
     
     
    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,210
    Thanks
    52
    Thanked 2,294 Times in 2,265 Posts

    Default Re: Java Help for a begginer

    how do i get it to obtain the name and color in one window?
    Have the user enter all the values you want on one line before pressing Enter.
    You'll have to separate them after the method returns them into a String.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. HW BEGGINER HELP !
    By begginerJava in forum Object Oriented Programming
    Replies: 5
    Last Post: April 14th, 2014, 11:54 AM
  2. Begginer : help would be much appreciated for this exercice!
    By linus101 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 20th, 2012, 05:31 PM
  3. Begginer Java - Bug in my code?
    By rk2010 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: March 7th, 2012, 07:12 AM
  4. help im a begginer
    By ivankov2 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 24th, 2011, 07:33 AM
  5. Any ideas for begginer?
    By SwEeTAcTioN in forum Java Theory & Questions
    Replies: 11
    Last Post: October 27th, 2009, 03:28 AM