Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-02-2007, 12:14 PM
Member
 
Join Date: Oct 2007
Posts: 9
jhetfield18 is on a distinguished road
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
Sponsored Links
  #2 (permalink)  
Old 11-02-2007, 05:33 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,022
hardwired is on a distinguished road
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
jhetfield18 is on a distinguished road
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
Sponsored Links
Reply


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

vB 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 +3. The time now is 02:29 PM.


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