Results 1 to 3 of 3
  1. #1
    siah0wn5a11 is offline Member
    Join Date
    Apr 2013
    Posts
    5
    Rep Power
    0

    Question Displaying Array Statistics Inside One JOptionPane

    I am trying to have the statistics from the math.random to be displayed in one JOptionPane message box. At this time it displays them in separate boxes.
    Java Code:
    import java.util.Random;
    import javax.swing.JOptionPane;
    public class dice
    {
    	public static void main(String args[])
    	{
    
    			int arr[] = new int[7];
    
    			for(int i = 1; i <= 10000; i++){
    			   //random numbers from 1 to 10:
    			   int r = ((int)(Math.random()*6) + 1);
    			   arr[r] ++;
    			}
    
    			for(int i = 1; i < 7; i++){
    			   JOptionPane.showMessageDialog(null, i + " was generated " +
    		 		  arr[i] + " times.");
    
    			}System.exit(0);
    	}
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default Re: Displaying Array Statistics Inside One JOptionPane

    The "message" parameter for the JOptionPane can be a single String (as in your code) but it can also be a Component (a JLabel, a JTable or whatever) or an Icon. It can also be an array of the previous types. That should get you started ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    siah0wn5a11 is offline Member
    Join Date
    Apr 2013
    Posts
    5
    Rep Power
    0

    Default Re: Displaying Array Statistics Inside One JOptionPane

    Sorry for late reply. I did look further into what you suggested and i managed to get everything working. Thanks

Similar Threads

  1. Replies: 2
    Last Post: 03-21-2013, 05:37 AM
  2. JList inside JScrollPane is not displaying
    By _SAS in forum AWT / Swing
    Replies: 2
    Last Post: 07-31-2011, 08:45 PM
  3. Replies: 10
    Last Post: 02-28-2010, 01:52 PM
  4. displaying tables in joptionpane
    By kaemonsaionji in forum New To Java
    Replies: 2
    Last Post: 02-26-2009, 06:53 AM
  5. Replies: 1
    Last Post: 07-31-2007, 04:01 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
  •