Reputation: 9
I have a really short and simple cuestion.
What must Y type on *.java file to show a png file on screen when I click on a button.
I've been searching and trying with intents and many otrher ways but I've not found the answer.
Thanks
Upvotes: 0
Views: 1619
Reputation: 324108
Read the Swing tutorial. The sections on How to Write an Action Listener
or How to Use Icons
would probably be a good place to start.
Upvotes: 1
Reputation: 72284
What do you mean by "on screen"? In a window? On its own? Have you got anything of the sort already? Generally speaking, you can use the ImageIO class to read from a PNG file into a BufferedImage:
BufferedImage image = ImageIO.read(new File("image.png"));
Then the quickest way is probably to attach the image to a label using ImageIcon:
JLabel imgLabel = new JLabel(new ImageIcon(image));
You can then add imgLabel
to a JFrame or similar which you can then display.
Upvotes: 1