/** * Applet used for drawing an image. * * @author Ruedi Hofer */ import java.applet.*; import java.awt.*; import java.util.*; //import netscape.javascript.*; public class AppletPaint extends Applet { Graphics zeichenbereich; Button clearButton; Button undoButton; Button undo10Button; Choice colorChooser; CheckboxGroup cbMode; Checkbox cbDel,cbDraw; private boolean drawMode=true; private Color zeichenfarbe=Color.black; private int last_x=0; private int last_y=0; private Vector vector = new Vector(); private final int appletWidth=400; private final int appletHeight=400; private final int drawAreaStartY=35; private final int drawAreaStartX=0; public String out="asdfasdf"; /** * Initializes the applet and sets up the widgets. * * @param void * @return void * @exception none */ public void init() { setBackground (Color.white); setForeground (Color.black); initDrawArea(); // CheckboxGroup mode cbMode=new CheckboxGroup(); cbDel=new Checkbox("Delete",cbMode,false); cbDraw=new Checkbox("Draw",cbMode,true); add(cbDel); add(cbDraw); // clear button clearButton=new Button("Clear"); add(clearButton); // undo button undoButton=new Button("Undo"); add(undoButton); // undo10 button undo10Button=new Button("Undo10"); add(undo10Button); // color chooser colorChooser=new Choice(); colorChooser.addItem("black"); colorChooser.addItem("white"); colorChooser.addItem("blue"); colorChooser.addItem("cyan"); colorChooser.addItem("green"); colorChooser.addItem("yellow"); colorChooser.addItem("orange"); colorChooser.addItem("magenta"); colorChooser.addItem("pink"); colorChooser.addItem("red"); add(colorChooser); } public boolean mouseDown(Event theEvent, int x, int y) { if (drawMode) { // End of line ArrayListElement aleend=new ArrayListElement(); aleend.setElement(-1,-1,zeichenfarbe); vector.addElement(aleend); // start new line ArrayListElement alenew=new ArrayListElement(); alenew.setElement(x,y,zeichenfarbe); vector.addElement(alenew); last_x=x; last_y=y; } else { // delete mode ArrayListElement ale=new ArrayListElement(); ale.setElement(x,y,zeichenfarbe); int i=vector.indexOf(ale); if (i!=-1) { // found an element to be removed vector.removeElementAt(i); // add an end of line element ArrayListElement aleend=new ArrayListElement(); aleend.setElement(-1,-1,zeichenfarbe); vector.insertElementAt(aleend, i); // System.out.println("Element "+i+" removed"); repaint(); } } return true; } public boolean mouseDrag(Event theEvent, int x, int y) { if (drawMode) { if (y>drawAreaStartY && ydrawAreaStartX && x