/Users/lyon/j4p/src/ip/gui/applets/NetImageSelectorApplet.java
|
1 package ip.gui.applets;
2
3 import java.applet.Applet;
4 import java.awt.*;
5 import java.net.MalformedURLException;
6 import java.net.URL;
7
8
9 public class NetImageSelectorApplet extends Applet {
10 Choice ch = new Choice();
11 Toolkit tk = Toolkit.getDefaultToolkit();
12 Label lb = new Label("Select Image");
13 Image image;
14 URL url;
15 String st =
16 "net.ftp://vinny.bridgeport.edu/home/net.ftp/pub/ipij/images/";
17
18
19 public void init() {
20 try {
21 url = new URL(st + "baboon.JPEG");
22 } catch (MalformedURLException e) {
23 e.printStackTrace();
24 }
25
26 image =
27 tk.getImage(url);
28
29 //
30 ch.addItem("baboon.JPEG");
31 ch.addItem("girl.JPEG");
32 ch.addItem("lena.JPEG");
33 ch.addItem("peppers.JPEG");
34
35 add(lb);
36 add(ch);
37 }
38
39 public void processEvent(AWTEvent e1) {
40 if (e1.getSource() instanceof Choice) {
41 try {
42 url = new URL(st + ch.getSelectedItem());
43 } catch (MalformedURLException e) {
44 e.printStackTrace();
45 }
46 image = tk.getImage(url);
47 repaint();
48 }
49 return;
50 }
51
52 public void update(Graphics g) {
53 paint(g);
54 }
55
56 public void paint(Graphics g) {
57 g.drawImage(image, 10, 40, this);
58 }
59 }