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); }} 一个类继承父类又实现了Runnable接口如何启动? 求助,今天在安装JDK1.6后javac运行不了? CSDN世态炎凉 jsp+servlet的问题 虚心向前辈请教,帮忙指点 将本地文件放入tree的组件,大家帮忙测试! 用SAXParser解析XML Dialog浮在TabPanel上的问题 JAVA读EXCEL文件的问题?详细主进………在线等待 请问这是什么错误啊,救救我!我已经急疯了!谢谢! 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);
}}