Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-02-2007, 12:14 PM
Member
 
Join Date: Oct 2007
Posts: 9
Rep Power: 0
jhetfield18 is on a distinguished road
Default About JOptionPane.showMessageDialog
Hi I was wondering if I could use a for(){} in a JOptionPane.showMessageDialog.To explain,let's say I have an array A,full of integers,and have done two different equations using the numbers from A and stored the the results in two arrays B,C one for each equation.Can I use one message box to print all the results in a form like this:
Number: ......
Result for equation no.1: ......
Result for equation no.2: ......

So it becomes like this in the message box:


Number: ......
Result for equation no.1: ......
Result for equation no.2: ......


Number: ......
Result for equation no.1: ......
Result for equation no.2: ......


Number: ......
Result for equation no.1: ......
Result for equation no.2: ......


Number: ......
Result for equation no.1: ......
Result for equation no.2: ......

..................................


Can I do this????Is there any way?Perhaps another message dialog command from another library that supports many results?

Regards,Nick
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-02-2007, 05:33 PM
hardwired's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 1,577
Rep Power: 4
hardwired is on a distinguished road
Default
JLabel supports html 3.2 (roughly).
Another option is to make up your own JDialog for this.
Code:
// intiialize your_components
// add listeners as needed
JDialog dialog = new JDialog(new Frame());
dialog.getContentPane().add(your_components)
dialog.pack();
dialog.setLocation(...)
dialog.setVisible(true);
// carry on as desired..
Code:
import javax.swing.*;
import java.util.Arrays;  // j2se 1.5+

public class OptionsTest {
    public static void main(String[] args) {
        int[] data = { 2, 3, 4, 5 };
        int[] squares = getSquares(data);
        int[] cubes = getCubes(data);
        System.out.printf("squares = %s%n", Arrays.toString(squares));
        System.out.printf("cubes   = %s%n", Arrays.toString(cubes));
        String s = formatResults(data, squares, cubes);
        JOptionPane.showMessageDialog(null, new JLabel(s), "Results",
                                      JOptionPane.PLAIN_MESSAGE);
    }

    static private int[] getSquares(int[] input) {
        int[] out = new int[input.length];
        for(int j = 0; j < input.length; j++) {
            out[j] = input[j]*input[j];
        }
        return out;
    }

    static private int[] getCubes(int[] input) {
        int[] out = new int[input.length];
        for(int j = 0; j < input.length; j++) {
            out[j] = input[j]*input[j]*input[j];
        }
        return out;
    }

    static String formatResults(int[] input, int[] one, int[] two) {
        // StringBuffer is the legacy alternative for j2se 1.4-.
        StringBuilder sb = new StringBuilder("<html>");
        for(int j = 0; j < input.length; j++) {
            sb.append("Number: " + input[j] + "<br>");
            sb.append("Result for equation no.1: " + one[j] + "<br>");
            sb.append("Result for equation no.2: " + two[j] + "<br><br>");
        }
        return sb.toString();
    }
}
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-02-2007, 11:45 PM
Member
 
Join Date: Oct 2007
Posts: 9
Rep Power: 0
jhetfield18 is on a distinguished road
Default
I guess that the new dialog idea would be better since i don't know html apart from a little here and there.So I'll search around and try that
Thx man!!!!!
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
JOptionPane (customizing) Java Tip Java Tips 0 03-14-2008 12:39 PM
JOptionPane dialog (Localizing) Java Tip Java Tips 0 03-14-2008 12:36 PM
About JOptionPane.showMessageDialog jhetfield18 Advanced Java 0 11-02-2007 11:56 AM
problems with JOptionPane oregon AWT / Swing 2 08-05-2007 06:58 PM
Displaying numbers per line on a JOptionPane.showMessageDialog screen zoe New To Java 1 07-31-2007 05:01 AM


All times are GMT +2. The time now is 04:39 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org