HelloWeb3
Rakendi HelloWeb3 seletab lahti Andres Tsengov. Siin on toodud ainult
näide ise:
import java.applet.*;
import java.awt.*;
public class HelloWeb3 extends Applet {
int messageX = 125, messageY = 95;
String theMessage;
Button theButton;
Color[] someColors = {
Color.black, Color.red, Color.green, Color.blue, Color.yellow };
int colorIndex;
public void init() {
theMessage = getParameter("message");
theButton = new Button("Change Color");
add(theButton);
}
public void paint(Graphics gc) {
gc.setColor(currentColor());
gc.drawString(theMessage, messageX, messageY);
}
public boolean action(Event e, Object arg) {
if (e.target == theButton) {
changeColor();
return true;
}
return false;
}
public boolean mouseDrag(Event evt, int x, int y) {
messageX = x;
messageY = y;
repaint();
return true;
}
synchronized private Color currentColor() {
return someColors[colorIndex];
}
synchronized private void changeColor() {
if (++colorIndex == someColors.length)
colorIndex = 0;
theButton.setForeground(currentColor());
repaint();
}
}
Kirjutage see tekst faili HelloWeb3.java, kompileerige, moodustage fail
HelloWeb3.html (täpselt analoogiline failiga HelloWeb2.html).
Siin see HelloWeb3.html on