SWT如何使用网络图片? 图片地址是 http://www.kitco.cn/cn/metals/gold/t24_au_cny_gram_450x275g.gif请问怎样将图片显示的软件上? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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 (); }} 你要监听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); }} 关于 repaint(),thread.sleep 的问题 关于JDBC+mysql中的longtext写入和读取问题 jar打包问题 才开始JAVA.请教一道作业题 在环境变量中如何将我的工作目录设为java编译时寻找原文件的默认路径? 以前下过一个中文的API,现在找不到了......请那位有的朋友给出下载地址或者邮给我 overload和overrid在java里有什么区别? 来java版报到,并提问 AWT高手请进 闲人莫入 关于用javamail群发邮件的问题? synchronized 方法是否可以重写? java rmi 是用来解决什么矛盾的?
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 ();
}}
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);
}}