• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Help - how do I display a list of arrays in a GUI

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there I'm having trouble with a java project, I need to display four arrays under privateVoidDisplayAllPurchases() which related to the Display All button in the GUI; private double [] cost , private String[] nameOfPurchase , private double[] weight and private double [] costPerKg in the DisplayText area
I tried DisplayTextArea.setText("\t" + nameOfPurchase[1][1]); to display one array, but It doesn't work

Could anyone give some help/tips?
would be appreciated



 
Ranch Hand
Posts: 135
5
Eclipse IDE Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Berry,
Warm Welcome to Ranch
Please look java.util.Arrays. This class also contains a static factory that allows arrays to be viewed as lists.
E.g. : (Example from Here.)

By the way, Please read this.
 
James Berry
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your time Jude!
thanks I had a look at the page and code you posted, but I couldn't get it to work under my displayAll method though
I did read it cheers

But thanks I'll try doing more research on the topic
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
James, have you learned How to Use Lists?
 
James Berry
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No I haven't researched it alone, thanks I'll check it out and do some study
 
Marshal
Posts: 73981
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome (again)

Don't try doing anything on a GUI until you can do it without. You should have some method of displaying those arrays from the command line. Better still, a method which returns a String (or similar) representing the output.
Are you really running parallel arrays? Good grief, that is really error‑prone. You should have a Purchase class, and that class should encapsulate cost weight, etc. Also it should have the usual methods, particularly toString, which enables you to display it on screen. Then you will get sensible output from the following two lines:-
System.out.println(myPurchase);
System.out.println(purchases[i]);

And once you have got that working from the command line/terminal, you will find it easier to show that on your GUI.
 
James Berry
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thankyou cambell, I have done a similar project which just outputs information through the Command Line Interface, which is easier
Yeah I am required to do four parallel arrays!
I can manage to output the array data into the CLI by using



I'll now try to move on to the GUI,still working on it, but cant seem to get it working :/
thanks for your time
 
Campbell Ritchie
Marshal
Posts: 73981
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The fact that you can beat parallel arrays into submission doesn't mean they are good code. What a shame that you have been told to use them rather than a proper Purchase class.
And don't even think of a GUI until you have your code working at the command line. You won't get a GUI to work if the underlying model doesn't work. Working means you can call a method and print its output. Like this:-
System.out.println(myPurchases.toString());
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic