• Post Reply Bookmark Topic Watch Topic
  • New Topic

Add image by pessing button  RSS feed

 
ilumi kinoko
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I have several pictures,
I want to add picture whenever I press the JButton.
Like:

1. (the board is empty)

2.button pressed (show a image)

3.press another button

4. and so on...


Even I press another button the previous images are still remain.
I want to do it on JFrame and on its certain area(I mean there is a certain area only images)
Can anybody give an example or direction?
Thank you
 
praneeth jayarathna
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ilumi kinoko try this,


praneeth j
(PCJT)

 
Rob Camick
Ranch Hand
Posts: 2828
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@praneeth,

When answer questions:

1) please use the code tags

2) Use proper Java naming conventions to teach proper habits. Variable names should NOT start with an upper case letter.
 
praneeth jayarathna
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[b]Rob Camick ,
Thank for your comment. Actually that's a mistake.sorry for about that.
 
ilumi kinoko
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much praneeth jayarathna

it works

I have new problem

What should i do if I like to

1. Press the same button

2. The image show again at x = x +50 with the original image remain?

I can not figure it out

please help me thanks
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Praneeth: Thanks for your effort, but here on JavaRanch we prefer to help people write the code themselves, instead of giving them ready-made answers. People learn a lot more when they discover how to write code themselves than when they are just handed out a complete answer. Please let people do their own homework. (And please UseCodeTags).

Ilumi: You'll need to remember where to draw the new image. What you could do is add a member variable to the class, and at each button click, you add 50 to the member variable and add an extra image at the position that the member variable indicates.

Can you try adding that to the code? Let us know how you're doing with it.
 
ilumi kinoko
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jesper

the pressing button to show image and move problem has been solved.

Answer can see at http://www.coderanch.com/t/533459/GUI/java/Having-two-paint#2419882

moved to Java » Swing / AWT / SWT / JFace

And still has some other problems

like: when i use repaint(), the previous image will gone as it move.
what should I do if I want the previous image remain?

Hope you guys can help me there


Really Thank you
 
ilumi kinoko
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,

My problem has been solved.
Thanks for Stephan van Hulst 's help

anyone who has similar problem can see the code at http://www.coderanch.com/t/533459/GUI/java/Having-two-paint#2419882

Thanks for JavaRanch and people who devotes to help here
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!