import java.awt.*; /* Przykladowy Applet, korzystajacy z java.awt realizuje rysowanie za pomoca myszki, przy kliknieciu - linii prostych - przy przeciaganiu - ciaglych */ public class Kreski extends java.applet.Applet { final int MAX= 1000; int x_pt[] = new int[MAX]; int y_pt[] = new int[MAX]; int n = 0; private int last_x = 0; private int last_y = 0; private Button kasuj; //inicjalizacja interfejsu public void init() { this.setBackground(Color.white); //kolor tla kasuj = new Button("Kasuj"); kasuj.setForeground(Color.black); kasuj.setBackground(Color.lightGray); this.add(kasuj); //dodanie przycisku } //obsluga zdarzenia - nacisniecie przycisku myszy public boolean mouseDown(Event evt, int x, int y) { last_x = x; last_y = y; x_pt[n] = x; y_pt[n] = y; n++; Graphics g = this.getGraphics(); for (int i = 0; i < n; i++) { g.fillOval(x_pt[i], y_pt[i] ,1,1); if(i>0) g.drawLine(x_pt[i-1] , y_pt[i-1] ,x_pt[i], y_pt[i]); //rysowanie linii z punktu do punktu } return true; } //obsluga zdarzenia - nacisniecia przycisku kasuj public boolean action(Event event, Object arg) { if (event.target == kasuj) { Graphics g = this.getGraphics(); Rectangle r = this.bounds(); g.setColor(this.getBackground()); g.fillRect(r.x, r.y, r.width, r.height); n=0; return true; } else return super.action(event, arg); } //obsluga zdarzenia - przeciagania myszy public boolean mouseDrag(Event evt, int x, int y){ Graphics g = this.getGraphics(); g.drawLine(last_x, last_y, x, y); //rysowanie linii ciaglej last_x = x; last_y = y; x_pt[n] = x; y_pt[n] = y; n++; return true; } }