Java The Complete Reference, Seventh Edition

(Greg DeLong) #1
public void init() {
setLayout(new BorderLayout());
Panel p = new Panel();
add(p, BorderLayout.SOUTH);
reset = new Button("Reset");
reset.addActionListener(this);
p.add(reset);
StringTokenizer st = new StringTokenizer(getParameter("filters"), "+");
while(st.hasMoreTokens()) {
Button b = new Button(st.nextToken());
b.addActionListener(this);
p.add(b);
}

lab = new Label("");
add(lab, BorderLayout.NORTH);

img = getImage(getDocumentBase(), getParameter("img"));
lim = new LoadedImage(img);
add(lim, BorderLayout.CENTER);

}

public void actionPerformed(ActionEvent ae) {
String a = "";

try {
a = ae.getActionCommand();
if (a.equals("Reset")) {
lim.set(img);
lab.setText("Normal");
}
else {
pif = (PlugInFilter) Class.forName(a).newInstance();
fimg = pif.filter(this, img);
lim.set(fimg);
lab.setText("Filtered: " + a);
}
repaint();
} catch (ClassNotFoundException e) {
lab.setText(a + " not found");
lim.set(img);
repaint();
} catch (InstantiationException e) {
lab.setText("couldn't new " + a);
} catch (IllegalAccessException e) {
lab.setText("no access: " + a);
}
}
}


Figure 25-7 shows what the applet looks like when it is first loaded using the applet tag
shown at the top of this source file.


Chapter 25: Images 773

Free download pdf