Skip to content
Sign upLog in
← Back to Community

Pictures?

Profile icon
KarmaIsKrazy

can one load an image on repl and have it show on the screen if so how

Answered by techde [earned 5 cycles]
View Answer
Voters
Profile icon
techde
Profile icon
KarmaIsKrazy
Comments
hotnewtop
Profile icon
techde

Yes you can do this, start with this:

import javax.swing.JFrame; import javax.swing.ImageIcon; import javax.swing.JLabel; class ShowPicture { public static void main(String args[]) { JFrame frame = new JFrame(); ImageIcon icon = new ImageIcon("androidBook.jpg"); JLabel label = new JLabel(icon); frame.add(label); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } }
Profile icon
techde

Then do something like this:

Purchase onePurchase = new Purchase();
Profile icon
techde

Then this:

JFrame frame = new JFrame(); ImageIcon icon = new ImageIcon("androidBook.jpg"); JLabel label = new JLabel(icon);
Profile icon
techde

Followed by this:

JFrame frame = new JFrame();
Profile icon
techde

At this point, we have started the frame, set the image variable, uploaded the image to the JFrame, and called the JFrame as a window instead of a JFrame.

Profile icon
techde
ImageIcon icon = new ImageIcon("androidBook.jpg");

This code creates the "Icon", that we said to go into the frame earlier.

Profile icon
techde
JLabel label = new JLabel(icon);

This creates a place to put the icon.

Profile icon
techde

And now we are done! This creates a frame then stores the image to a "Database", takes that content and displays it on the screen!

Profile icon
thomashebert2

It's both beautiful and important. This blog is rather fascinating. Links may be quite useful. The help and information you provided to many people was really beneficial. Please wait for your tiny fishing unblocked postings.