Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

text field

 
ksnewbie
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am really green at programming in Java, I hope someone can help.
My objective is to create a sort of photo album, to insert a name of a image in a text field and the image then appears.
I was going about it like this:
public void paint(Graphics g) {
if (imageField = "picture1")
g.drawImage(image1, 20,20,100, 100, this);
else
g.drawImage(image2, 20,20,100, 100, this);
but I get an error for incompatable types.
Any suggestions??
Should I be placing it in an actionPerformed method?
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Your programming error is in using = instead of == . Your if statement is trying to perform an assignment and you probably just want a compare.
Your second is that == won't work as you expect for a String. You should use the equals method to compare one string to another.
NOTE: Your name is not a valid one here at the ranch. Please read the naming policy and re-register with a professional name (i.e., first name + space + last name).
Regards,
Manfred.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic