1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mypkg;
/**
*
* @author hamdi
*/ import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
public class ChargerImage
{
public static void main(String[] args)
{
Fenetre fenetre = new Fenetre();
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.show();
}
}
class Fenetre extends JFrame
{
public Fenetre()
{System.out.println("fenetre01");
Container leContenant = getContentPane();
leContenant.setLayout(new FlowLayout());
setSize(800,800);
AffichageImage image = new AffichageImage();
leContenant.add(image);
System.out.println("fenetre02");
}
}
class AffichageImage extends Canvas
{
Image image;
public AffichageImage()
{URLConnection con=null;
System.out.println("Image01");
try {
// con = new URL("http://maps.google.com/maps/api/staticmap?sensor=true¢er=italie&zoom=5&size=512x512&maptype=roadmap").openConnection();
con = new URL("http://maps.googleapis.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=14&size=320x320&maptype=roadmap&sensor=false").openConnection();
InputStream is = con.getInputStream();
byte[] bytes = new byte[con.getContentLength()];
is.read(bytes);
is.close();
Toolkit tk = getToolkit();
image = tk.createImage(bytes);
tk.prepareImage(image, -1, -1, null);
prepareImage(image, this);
} catch (IOException ex) {
System.out.println("haha") ;
System.out.println( con.equals(null) ) ;
}
System.out.println("Image02");
}
public void paint(Graphics g)
{System.out.println("Paint01");
//for(int i=0; i>50;i++){
g.drawImage(image, 0, 0, this);
// }
System.out.println("Paint02");
}
@Override
public boolean imageUpdate(Image image, int info, int x, int y, int l, int h)
{System.out.println("ImageUpload01");
setSize(800,800);
if ((info & (ALLBITS)) != 0)
{
repaint();
System.out.println("ImageUpload02f");
return false;
}
else
{ System.out.println("ImageUpload02t");
return true;
}
}
} |
Partager