Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Outputting correct image from array.

 
touchai vang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
New to java.  Any help is greatly appreciated.  This is a translation assignment where we are to create 3 arrays, get user input (a simple word like 'man'), translate it to a second language and output a photo corresponding with the word translated.  I've written the code that will translate an input, but I stuck on how to output a photo.  Below is the code that I have written thus far.


 
Campbell Ritchie
Sheriff
Posts: 51446
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
This question would fit better in our Applets forum so I shall move it.
Thank you for using code tags, but you have some formatting problems. Don't write so many empty lines. You can delete lines 48-51 and 76, 114 and 116. You have inconsistent indentation in lines 69-72, so you cannot tell whether there shou‍ld really be four }s in lines 74-78. Break your arrays into several lines because the long lines affect legibility of the whole discussion, line 16 being the worst. I think this is what it shou‍ld look like:-Why are you using multiple arrays in parallel? That is error‑prone and non‑object‑oriented programming. You shou‍ld have some sort of class which encapsulates the English name, the Hmong name and the picture. I can't unfortunately think of a good name for that class just at the moment. Sorry. Why are you writing the different names in lines 104-113? Why don't you simply go through the array and print out the names; you can have a local variable for yPosition and add 20 to it each time.

Why are you using an applet in the first place? Nobody else uses them any more.
 
touchai vang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for moving my question to the appropriate forum Ritchie.  And thank you for all the great advice.  I am taking an Intro to Java course so we're bound to using applets for now.  Lines 104-113 is to display a list of words on the applet that a user may choose from to translate into Hmong.  So as the code stands now, there is a list of words a user can choose to translate, there are two textfields, first one being the word the user enters, the second textfield outputs the tanslation.  I am stuck however, on how to ouput a photo from the array photo[]. 
 
Knute Snortum
Bartender
Pie
Posts: 2904
62
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can use an ImageIcon (that's a link) to do that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic