swing Java tutorial - doesn't work, how to resolve?
GregBeutler

https://repl.it/@GregBeutler/brokentutorialJavaSWing

I copied the jswing Java tutorial and it doesn't work!

pls advise.
Greg

You are viewing a single comment. View All
EpicGamer007

Hey sorry for my bad tutorial. You need some imports that I forgot to mention. Really sorry

here are the imports:

add this to your code and hopefully this works, really sorry about making that mistake. Hope this helps :)

GregBeutler

@AbhayBhat
thanks that works.

any more tutorials?
I'm trying to take the input of the button
and make the gui display an image.
just like the FB game 'Which disney princess are you?"

EpicGamer007

@GregBeutler, , yes i do have more tutorials coming up :)

For what you are planning on doing, you need graphics. I think you should first do Image toDraw = new BufferedImage("res/image.jpg");(Research more about buffered images), then i suggest is creating a button, then adding an action listener which gets the graphics for you using this method: Graphics g = frame.getGraphics(); Note, this is a very bad way of doing graphics. I will show a better way in my upcoming tutorials.. ok, with the g object, you can do g.drawImage(0, 0, toDraw, null); which draws the image at 0, 0 on the screen.

Yeah...
That is how i suggest doing it, if you have any other questions, feel free to contact me :).

Please mark my answer as correct if it helps :)

PattanAhmed

@GregBeutler Hi,
Check this website to learn JavaSwing
Click here
Thanks!

Hope this helps