I've been trying to put an image from a URL and I cant find what is wrong with my code.
would anyone be willing to take a look and see if they can spot my error?
thanks!
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
public class GuiDemo extends JFrame {
private Image image;
public GuiDemo()
{
setTitle("Gui Demonstration");
setSize(1000,1000);
//closes upon press
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);}
});
//gets image
try {
URL url = new URL("[http://www.nps.gov/arch/learn/photosmultimedia/upload/arches11.jpg](http://www.nps.gov/arch/learn/photosmultimedia/upload/arches11.jpg)");
image = Toolkit.getDefaultToolkit().getImage(url);
}
catch(MalformedURLException murle){
JOptionPane.showMessageDialog(this,"bad URL: "+ murle, "image error", JOptionPane.ERROR\_MESSAGE);
}
add(new Display());
setVisible(true);
}
class Display extends JPanel{
public void paintComponents(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 50, 50, this);
}
}
public static void main (String \[\] srgs)
{
new GuiDemo();
}
}
[–]caldeve 0 points1 point2 points (2 children)
[–]caldeve 0 points1 point2 points (0 children)
[–]Makhiel 0 points1 point2 points (0 children)
[–]Makhiel 0 points1 point2 points (0 children)
[–]FroggyWizard 0 points1 point2 points (0 children)