Лекция: Аплет для изменения цвета фона
import java.awt.*;
import java.applet.*;
public class fon extends Applet
{
public void init()
{
add(new Button(«red»));
add(new Button(«blue»));
}
public boolean action(Event evt, Object whatAction)
{
if (!(evt.target instanceof Button))
{
return false;
}
String buttonLabel=(String) whatAction;
if (buttonLabel==«red»)
{
setBackground(Color.red);
}
else if (buttonLabel==«blue»)
{
setBackground(Color.blue);
}
repaint();
return true;
}
}
<html>
<body>
<applet code=«fon.class» width=400
height=200>
</applet>
</body>
</html>