Results 1 to 12 of 12
  1. #1
    nome is offline Member
    Join Date
    Apr 2011
    Posts
    9
    Rep Power
    0

    Default JOptionPane does not execute here, why?

    Java Code:
    import javax.swing.JOptionPane;
    import java.util.Scanner;
    public class Strings {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		Scanner input = new Scanner(System.in);
    		System.out.println("Enter a word...");
    		String s1 = input.next();
    		System.out.println("s1 is " + s1);
    	
    		String message = "Java is fun";
    		JOptionPane.showMessageDialog(null, message);
    
    	}
    
    }
    Last edited by Eranga; 01-20-2012 at 03:00 AM. Reason: code tags added

  2. #2
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    3

    Default Re: JOptionPane does not execute here, why?

    It does on my computer ?

  3. #3
    nome is offline Member
    Join Date
    Apr 2011
    Posts
    9
    Rep Power
    0

    Default Re: JOptionPane does not execute here, why?

    Ok. I cmd the Strings class and it does work. The problem happens on Eclipse/helios. I run the app and after I enter the word on the console no dialog box.

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

    Default Re: JOptionPane does not execute here, why?

    What do you mean by "I cmd the String class"? Specifically, what does "cmd" mean? And also, I too get the dialog. Please give any more details of what's going on if possible.

  5. #5
    nome is offline Member
    Join Date
    Apr 2011
    Posts
    9
    Rep Power
    0

    Default Re: JOptionPane does not execute here, why?

    By cmd I meant going to C://javaProject/bin/Strings.class and run the java Strings command. That works fine. The problem I am having is in Eclipse.

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

    Default Re: JOptionPane does not execute here, why?

    Quote Originally Posted by nome View Post
    By cmd I meant going to C://javaProject/bin/Strings.class and run the java Strings command. That works fine. The problem I am having is in Eclipse.
    Hm, it works fine for me in Eclipse Indigo release.

  7. #7
    nome is offline Member
    Join Date
    Apr 2011
    Posts
    9
    Rep Power
    0

    Default Re: JOptionPane does not execute here, why?

    Tried on Indigo on a different machine and same problem.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default Re: JOptionPane does not execute here, why?

    I have test the same with Eclipse Helios and works fine. However the message box not popups on the IDE, it could be behind it. There is nothing related with IDE in your code. Check it again.

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default Re: JOptionPane does not execute here, why?

    Quote Originally Posted by Fubarable View Post
    Hm, it works fine for me in Eclipse Indigo release.
    It works fine on Eclipse Helios as well, which is the version I am using right now.

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

    Default Re: JOptionPane does not execute here, why?

    Quote Originally Posted by nome View Post
    Tried on Indigo on a different machine and same problem.
    Since I can't replicate your problem, I can't understand it -- sorry.

    But just for grins, what if you change input.next() to input.nextLine() so you fully handle the end of line token:

    Java Code:
    String s1 = input.nextLine();
    And if that doesn't work, what if you specify the JOptionPane to show up on the Swing thread, the EDT:

    Java Code:
    import javax.swing.JOptionPane;
    import javax.swing.SwingUtilities;
    import java.util.Scanner;
    
    public class Strings {
    
       public static void main(String[] args) {
          Scanner input = new Scanner(System.in);
          System.out.println("Enter a word...");
          String s1 = input.nextLine();
          System.out.println("s1 is " + s1);
    
          final String message = "Java is fun";
          SwingUtilities.invokeLater(new Runnable() {
             public void run() {
                JOptionPane.showMessageDialog(null, message);
             }
          });
    
       }
    
    }

  11. #11
    nome is offline Member
    Join Date
    Apr 2011
    Posts
    9
    Rep Power
    0

    Default Re: JOptionPane does not execute here, why?

    Eranga et all..
    Sorry, I feel like such a moron, the popup does work, it's just behind the window. It's curious thought that it does that. If I was to call the JOptionPane all by itself it pops up in front, regularly.
    Thanks for your patience.

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default Re: JOptionPane does not execute here, why?

    You are welcome.

    If something going wrong where I have confidence on that couldn't be, I am always looking into the basis. That practice makes my life so easy.

Similar Threads

  1. How to execute jsp
    By Ravidasineni1234 in forum Java Software
    Replies: 3
    Last Post: 05-07-2011, 01:01 PM
  2. How do I get my while loop to execute?
    By _inase in forum New To Java
    Replies: 2
    Last Post: 02-28-2011, 02:29 AM
  3. how to execute a jar file
    By renu in forum New To Java
    Replies: 2
    Last Post: 02-03-2011, 04:09 PM
  4. cannot execute EJB application.
    By JavaEmpires in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 07-17-2008, 09:53 AM
  5. why does not execute this?
    By aleplgr in forum New To Java
    Replies: 6
    Last Post: 08-01-2007, 11:37 AM

Tags for this Thread

Posting Permissions

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