i would like to know how to display a picture upon clicking a button..
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
i would like to know how to display a picture upon clicking a button..
javanand (June 25th, 2013)
Use an ActionListener for the button, load the image and display it in a JLabel.
Rakshith (June 25th, 2013)
You'll have to use multiple libraries, awt and swing. Here's some easy anti-OOP code I created for you:
...
If you don't understand something. feel free to ask me. Also, you should create a folder in the project (if you're using an IDE) called "res". This is where you put your images/etc. Then, to tell Java were the image is, simply write "res/image.png". Take note that actionPerformed cannot be placed in the main.
Feel free to hit the "Thanks" (displayed to the left of the screen below my info) or something. This is the first time I'm helping someone out with code!
Note: This thread does not belong to "What's wrong with my code?". Consider moving it to Java Theory & Questions!
Last edited by Cronus; June 24th, 2013 at 05:49 PM. Reason: EDIT: Shortened several comments + changed sentences and made them more understandable
Rakshith (June 25th, 2013)
Great spoon feeding!
thanks a lot i would like to let you know,dat iam familar with java ide,iam using eclipse currently as iam still a beginner.will implement the code and build on it.
will surely contact you if i had any further doubts.
thanks a lot
Indeed. Cronus, I do recommend reading
Announcements - What's Wrong With My Code?
and
http://www.javaprogrammingforums.com...n-feeding.html
I know what it is, I got a little excited to make example code to someone for the first time. "My thoughts exactly" wasn't maybe the most correct answer, but I have something to say in my defense: "#YOLO #SWAG". I rest my case.
--- Update ---
I'm glad to help. Spoon feeding is illegal in 42 countries, though. So you'll have to make it by yourself next time.