Results 1 to 3 of 3
- 11-02-2007, 11:14 AM #1
Member
- Join Date
- Oct 2007
- Posts
- 9
- Rep Power
- 0
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
- 11-02-2007, 04:33 PM #2
JLabel supports html 3.2 (roughly).
Another option is to make up your own JDialog for this.
Java 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..
Java 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(); } }
- 11-02-2007, 10:45 PM #3
Member
- Join Date
- Oct 2007
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
JOptionPane (customizing)
By Java Tip in forum Java TipReplies: 0Last Post: 03-14-2008, 11:39 AM -
JOptionPane dialog (Localizing)
By Java Tip in forum Java TipReplies: 0Last Post: 03-14-2008, 11:36 AM -
About JOptionPane.showMessageDialog
By jhetfield18 in forum Advanced JavaReplies: 0Last Post: 11-02-2007, 10:56 AM -
problems with JOptionPane
By oregon in forum AWT / SwingReplies: 2Last Post: 08-05-2007, 05:58 PM -
Displaying numbers per line on a JOptionPane.showMessageDialog screen
By zoe in forum New To JavaReplies: 1Last Post: 07-31-2007, 04:01 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks