• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Add image by pessing button

 
Greenhorn
Posts: 19
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ilumi kinoko try this,


praneeth j
(PCJT)

 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Jesper

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

Answer can see at https://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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 https://coderanch.com/t/533459/GUI/java/Having-two-paint#2419882

Thanks for JavaRanch and people who devotes to help here
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic