File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Need to Print out put to Dialog box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need to Print out put to Dialog box" Watch "Need to Print out put to Dialog box" New topic
Author

Need to Print out put to Dialog box

mike statham
Greenhorn

Joined: Feb 24, 2012
Posts: 16
I not or dont know how to convert to a dialog box out put print!



I need to print this information to a dialog box

Total number of excuses: 264
The Excuse Water spilled on it had the max numer of excuses
The Excuse A tornado got it had the min numer of excuses

Excuse name # of excuses
My dog ate it 15
It burned 12
I lost it 18
I ate it 23
It fell down the sewer 16
It shredded 44
I forgot it 19
I can't remember 17
Water spilled on it 0
A tornado got it 1
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
at the moment you're using a bunch of System.out.println's to print:

Total number of excuses: 264
The Excuse Water spilled on it had the max numer of excuses
The Excuse A tornado got it had the min numer of excuses

Excuse name # of excuses
My dog ate it 15
It burned 12
I lost it 18
I ate it 23
It fell down the sewer 16
It shredded 44
I forgot it 19
I can't remember 17
Water spilled on it 0
A tornado got it 1


continue with the current program, but try to print all of the above in a single println,
which would mean using a StringBuffer, or StringBuilder to create a single String of the above
so it would be
String message = [will end up as all of the above];
System.out.println(message);

now when it prints out exactly as above, you change
System.out.println(message);
to
javax.swing.JOptionPane.showMessageDialog(null,message);
mike statham
Greenhorn

Joined: Feb 24, 2012
Posts: 16
Michael Dunn wrote:at the moment you're using a bunch of System.out.println's to print:

Total number of excuses: 264
The Excuse Water spilled on it had the max numer of excuses
The Excuse A tornado got it had the min numer of excuses

Excuse name # of excuses
My dog ate it 15
It burned 12
I lost it 18
I ate it 23
It fell down the sewer 16
It shredded 44
I forgot it 19
I can't remember 17
Water spilled on it 0
A tornado got it 1


continue with the current program, but try to print all of the above in a single println,
which would mean using a StringBuffer, or StringBuilder to create a single String of the above
so it would be
String message = [will end up as all of the above];
System.out.println(message);

now when it prints out exactly as above, you change
System.out.println(message);
to
javax.swing.JOptionPane.showMessageDialog(null,message);



Ok, I've re wrote my code, but instead of printint in a dialog box like:

Total number of excuses: 264
The Excuse Water spilled on it had the max numer of excuses
The Excuse A tornado got it had the min numer of excuses

Excuse name # of excuses
My dog ate it 15
It burned 12
I lost it 18
I ate it 23
It fell down the sewer 16
It shredded 44
I forgot it 19
I can't remember 17
Water spilled on it 0
A tornado got it 1



it displays in a straight line!



Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38340
    
  23
I don’t know about the output, but I can see lots more, I am afraid.
Why are you not creating an object? You are supposed to be learning object-oriented programming. There ought to be an Excuse object, which can have a text and howOftenUsed fields, which you can put into an array. You can give it a toString() method and use that to print it. You can even create a Comparator<Excuse> class, so you can sort your array (or a copy of it). You can get rid of those many uses of the keyword static.
Your input looks iffy. You are using Scanner#inext and parseInt, as if you didn’t know about the Scanner#nextInt method, and two lines later you are calling nextInt, which will simply remove the next valid input number. I have told somebody else to create a utility class for keyboard input, and that he could write a method in this class which validates ints within a certain range. That might be useful for you. Please search for it.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38340
    
  23
And why are you resetting nums[i] to 100? That is obviously why the excuse never used comes out as used most frequently. Don’t use parallel arrays like that; they are error-prone.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need to Print out put to Dialog box