应该是满足了吧
import java.awt.*;
import java.applet.*;
import java.net.URL;
import java.awt.image.ImageProducer;
public class AppletTest extends Applet {
private Image i;
String urlString = "http://www.baidu.com/img/logo.gif"; // 图片地址
Button b1 = new Button("zoom In");
Button b2 = new Button("zoom Out");
int a = 80;
int b = 80;
public void init() {
try {
URL url = new URL(urlString);
i = this.createImage((ImageProducer) url.getContent());
add(b1);
add(b2);
} catch (Exception e) {
e.printStackTrace();
}
}
public boolean action(Event evt, Object arg) {
if(evt.target.equals(b1))
zoomIn();
else if(evt.target.equals(b2))
zoomOut();
// Let the base class handle it:
else
return super.action(evt, arg);
return true; // We've handled it here
}
public void zoomIn(){
a += 10;
b += 10;
repaint();
}
public void zoomOut(){
a -= 10;
b -= 10;
repaint();
}
public void paint(Graphics g) {
g.drawImage(i, 20, 40, a, b, this);
}
}