图片地址是  http://www.kitco.cn/cn/metals/gold/t24_au_cny_gram_450x275g.gif
请问怎样将图片显示的软件上?

解决方案 »

  1.   

    public class Snippet {
    public static void main(String[] args) throws IOException {
    Display display = new Display ();
    Shell shell = new Shell (display);
    URL url = new URL("http://www.kitco.cn/cn/metals/gold/t24_au_cny_gram_450x275g.gif ");
    Image image = new Image(display, url.openStream()); shell.setBackgroundImage(image);
    shell.setBounds(100, 100, image.getImageData().width + 10, image.getImageData().height + 30);
    shell.open ();
    while (!shell.isDisposed ()) {
    if (!display.readAndDispatch ()) display.sleep ();
    }
    display.dispose ();
    }}
      

  2.   

    你要监听resize事件并缩放图片
    public class Snippet {
    public static void main(String[] args) throws IOException {
    final Display display = new Display ();
    Shell shell = new Shell (display);
    URL url = new URL("http://www.kitco.cn/cn/metals/gold/t24_au_cny_gram_450x275g.gif");
    final Image image = new Image(display, url.openStream()); shell.setBackgroundImage(image);
    shell.setBounds(0, 0, image.getImageData().width + 10, image.getImageData().height + 30); shell.addControlListener(new ControlListener(){ @Override
    public void controlMoved(ControlEvent controlevent) {
    // TODO Auto-generated method stub } @Override
    public void controlResized(ControlEvent event) {
    Shell shell = (Shell) event.widget;
    int width = shell.getBounds().width;
    int height = shell.getBounds().height;
    ImageData data = image.getImageData();
    data = scale(data, width, height);
    Image image = new Image(display, data);
    shell.setBackgroundImage(image);
    } });
    shell.open ();
    while (!shell.isDisposed ()) {
    if (!display.readAndDispatch ()) display.sleep ();
    }
    display.dispose ();
    } public static ImageData scale(ImageData srcData, int width, int height) {
    if (width <= 0)
    throw new IllegalArgumentException("Invalid width :" + width);
    if (height <= 0)
    throw new IllegalArgumentException("Invalid height :" + height);
    return srcData.scaledTo(width, height);
    }}